input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
import itertools
N,X,Y=list(map(int, input().split()))
l=list(range(1,N+1))
for k in range(1, N):
cnt=0
for p in itertools.combinations(l, 2):
a=p[1]-p[0]
b=abs(p[1]-Y)+abs(p[0]-X)+1
if k==min(a,b):cnt+=1
print(cnt)
|
import itertools
N,X,Y=list(map(int, input().split()))
l=list(range(1,N+1))
cnt=[0]*(N-1)
for p in itertools.combinations(l, 2):
a=p[1]-p[0]
b=abs(p[1]-Y)+abs(p[0]-X)+1
cnt[min(a,b)-1]+=1
for k in cnt:
print(k)
|
p02726
|
import itertools
N,X,Y=list(map(int, input().split()))
l=list(range(1,N+1))
cnt=[0]*(N-1)
for p in itertools.combinations(l, 2):
a=p[1]-p[0]
b=abs(p[1]-Y)+abs(p[0]-X)+1
cnt[min(a,b)-1]+=1
for k in cnt:
print(k)
|
N,X,Y=list(map(int, input().split()))
ans=[0]*(N-1)
for i in range(1,N):
for j in range(i+1, N+1):
ans[min(j-i, abs(j-Y)+abs(i-X)+1)-1]+=1
for a in ans:
print(a)
|
p02726
|
n,x,y=list(map(int,input().split()))
ans=[0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
dist1=j-i
dist2=abs(x-i)+abs(y-j)+1
dist3=abs(y-i)+abs(x-j)+1
d=min(dist1,dist2,dist3)
ans[d]+=1
for i in range(1,n):
print((ans[i]))
|
N,X,Y = list(map(int, input().split()))
cnt = [0]*N
for i in range(1,N+1):
for j in range(i+1,N+1):
if abs(X-i)+abs(j-Y)+1 < j-i:
cnt[abs(X-i)+abs(j-Y)+1] += 1
else:
cnt[j-i] += 1
for i in range(1,N):
print((int(cnt[i])))
|
p02726
|
n,x,y = list(map(int,input().split()))
def largest(a,b,c):
if a <= b:
if a<= c:
return a
else:
return c
else:
if b<=c:
return b
else:
return c
def absol(d):
if d < 0:
return -d
else:
return d
def dist(i,j):
return largest(j-i, absol(x-i) + absol(y-j) + 1, absol(x-j) + absol(y-i) + 1)
listlist = [0]*(n-1)
for i in range(1,n):
for j in range(i+1,n+1):
distance = dist(i,j)
listlist[distance-1] = listlist[distance-1] + 1
for k in listlist:
print(k)
|
n,x,y = list(map(int,input().split()))
def dist(i,j):
return min(j-i, abs(x-i) + abs(y-j) + 1, abs(x-j) + abs(y-i) + 1)
listlist = [0]*(n-1)
for i in range(1,n):
for j in range(i+1,n+1):
distance = dist(i,j)
listlist[distance-1] = listlist[distance-1] + 1
for k in listlist:
print(k)
|
p02726
|
from collections import defaultdict
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
d = defaultdict(int)
for i in range(n-1):
for j in range(i+1, n):
path = min([j-i, abs(x-i)+abs(y-j)+1, abs(x-j)+abs(y-i)+1])
d[path] += 1
for i in range(1, n):
print((d[i]))
|
from collections import defaultdict
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
d = defaultdict(int)
for i in range(n-1):
for j in range(i+1, n):
path = min(j-i, abs(x-i)+abs(y-j)+1)
d[path] += 1
for i in range(1, n):
print((d[i]))
|
p02726
|
N,X,Y = (int(i) for i in input().split())
NUM = [0] * (N-1)
for i in range(1,N):
for j in range(i+1,N+1):
num = min(abs(i-j), abs(X-i)+1+abs(Y-j), abs(Y-i) + 1 + abs(X-j))
if (num < N):
NUM[num-1] += 1
for i in range(len(NUM)):
print((NUM[i]))
|
def main():
n, x, y = (int(i) for i in input().split())
num_list = [0] * (n - 1)
for i in range(1, n):
for j in range(i + 1, n + 1):
num = min(abs(i - j), abs(x - i) + 1 + abs(y - j), abs(y - i) + 1 + abs(x - j))
if (num < n):
num_list[num - 1] += 1
for i in range(len(num_list)):
print((num_list[i]))
if __name__ == '__main__':
main()
|
p02726
|
N, X, Y = list(map(int, input().split()))
for k in range(1,N):
ans = 0
for i in range(1,N):
for j in range(i,N+1):
min_dis = min((j-i), abs(X-i)+1+abs(j-Y))
if min_dis == k:
ans += 1
print(ans)
|
N, X, Y = list(map(int, input().split()))
memo = [0] *(N)
for i in range(1, N):
for j in range(i, N + 1):
min_dis = min((j - i), abs(X - i) + 1 + abs(j - Y))
memo[min_dis] += 1
for k in range(1,N):
print((memo[k]))
|
p02726
|
def warshall_floyd(d):
#d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
n,X,Y = list(map(int,input().split()))
d = [[float("inf")]*n for i in range(n)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
ans = [0]*(n-1)
for i in range(n-1):
d[i][i+1] = 1
d[i+1][i] = 1
d[Y-1][X-1] = 1
d[X-1][Y-1] = 1
for i in range(n):
d[i][i] = 0 #自身のところに行くコストは0
d = warshall_floyd(d)
for i in range(n):
for j in range(i+1,n):
ans[d[i][j]-1] += 1
for i in range(n-1):
print((ans[i]))
|
N,X,Y = list(map(int,input().split()))
X -= 1
Y -= 1
ans = [0]*(N)
d = [[N]*N for i in range(N)]
for i in range(N):
for j in range(i,N):
if i<=X and Y<=j:
d[i][j] = X-i+j-Y+1
else:
d[i][j] = min(abs(i-X)+abs(Y-j)+1,j-i)
for i in range(N):
for j in range(i+1,N):
ans[d[i][j]] += 1
for i in range(1,N):
print((ans[i]))
|
p02726
|
n,x,y = list(map(int,input().split()))
ko = [0 for i in range(10**4)]
for i in range(1,n):
for j in range(i+1,n+1):
c1 = j-i
if i<=x and y<=j:
c2 = (x-i)+1+(j-y)
elif i<=x and j<y:
c2 = (x-i)+1+(y-j)
elif x<i and y<=j:
c2 = (i-x)+1+(j-y)
else:
c2 = (i-x)+1+(y-j)
ko[min(c1,c2)] += 1
# print(i,j,j-i,c1,c2,ko[:10])
for i in range(1,n):
print((ko[i]))
|
n,x,y = list(map(int,input().split()))
ko = [0 for i in range(10**4)]
for i in range(1,n):
for j in range(i+1,n+1):
c1 = j-i
c2 = abs(x-i)+1+abs(y-j)
ko[min(c1,c2)] += 1
# print(i,j,j-i,c1,c2,ko[:10])
for i in range(1,n):
print((ko[i]))
|
p02726
|
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
if __name__ == '__main__':
n,x,y = list(map(int, input().split()))
costList = [0]*n
for i in range(1, n):
for j in range(i+1, n+1):
if j > i:
minCost = min(abs(i-j),abs( x-i) +abs(y-j)+1,abs( y-i) +abs(x-j)+1 )
costList[minCost] = costList[minCost]+1
for i in range(n):
if i >0:
print((costList[i]))
|
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
if __name__ == '__main__':
n,x,y = list(map(int, input().split()))
costList = [0]*n
for i in range(1, n):
for j in range(i+1, n+1):
if j > i:
minCost = min(abs(i-j),abs( x-i) +abs(y-j)+1,abs( y-i) +abs(x-j)+1 )
costList[minCost] +=1
for i in range(n):
if i >0:
print((costList[i]))
|
p02726
|
n,x,y = list(map(int,input().split()))
k = [0]*(n)
for i in range(1,n):
for j in range(i+1,n+1):
if i < x and j <= x:
k[j-i] += 1
elif i >= y and j > y:
k[j-i] += 1
elif x <= i < y and x< j <= y:
ind = min(j-i,i-x+y-j+1)
k[ind] += 1
elif i < x and x < j <= y:
ind = min(j-i,x-i+y-j+1)
k[ind] += 1
elif x <= i < y and y < j:
ind = min(j-i,i-x+1+j-y)
k[ind] += 1
elif i< x and j > y:
ind = x - i + 1 + j - y
k[ind] += 1
for i in range(1,n):
print((k[i]))
|
n,x,y = list(map(int,input().split()))
k = [0]*(n)
for i in range(1,n):
for j in range(i+1,n+1):
ind = min(j-i,abs(x-i) + abs(j-y) + 1)
k[ind] += 1
for i in range(1,n):
print((k[i]))
|
p02726
|
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [eval(input()) for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [int(eval(input())) for i in range(n)]
class Math():
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def divisor(n):
res = []
i = 1
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
@staticmethod
def round_up(a, b):
return -(-a // b)
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n ** 0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
class PriorityQueue:
def __init__(self, l=[]):
self.q = l
heapq.heapify(self.q)
return
def push(self, n):
heapq.heappush(self.q, n)
return
def pop(self):
return heapq.heappop(self.q)
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
MOD = int(1e09) + 7
INF = int(1e15)
def main():
# sys.stdin = open("sample.txt")
N, X, Y = Scanner.map_int()
X -= 1
Y -= 1
M = [[0 for _ in range(N)] for _ in range(N)]
for k in range(N):
for i in range(N):
M[k][i] = max(0, -(k - i))
if k >= Y:
continue
if k <= X:
for i in range(Y, N):
M[k][i] = M[k][X] + 1 + (i - Y)
for i in range(X, Y):
M[k][i] = min(M[k][X] + (i - X), M[k][Y] + (Y - i))
else:
for i in range(max(k, X), Y + 1):
M[k][i] = min(abs(k - i), abs(X - i) + 1 +
abs(Y - k), abs(Y - i) + 1 + abs(X - k))
for i in range(Y, N):
M[k][i] = M[k][Y] + (i - Y)
for i in range(1, N):
ans = 0
for m in M:
ans += m.count(i)
print(ans)
if __name__ == "__main__":
main()
|
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
class Math():
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def divisor(n):
res = []
i = 1
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
@staticmethod
def round_up(a, b):
return -(-a // b)
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n ** 0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
@staticmethod
def fact(N):
res = {}
tmp = N
for i in range(2, int(N ** 0.5 + 1) + 1):
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
if cnt > 0:
res[i] = cnt
if tmp != 1:
res[tmp] = 1
if res == {}:
res[N] = 1
return res
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
MOD = int(1e09) + 7
INF = int(1e15)
def dist(i, j, X, Y):
if j <= X:
return j - i
if i >= Y:
return j - i
if i <= X < Y <= j:
return X - i + 1 + j - Y
if X <= i < j <= Y:
d1 = j - i
d2 = i - X + 1 + Y - j
return min(d1, d2)
if i <= X <= j <= Y:
d1 = j - i
d2 = X - i + 1 + Y - j
return min(d1, d2)
else:
d1 = j - i
d2 = i - X + 1 + j - Y
return min(d1, d2)
def solve():
N, X, Y = Scanner.map_int()
ans = [0 for _ in range(1, N + 1)]
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
d = dist(i, j, X, Y)
ans[d] += 1
print(*ans[1:], sep='\n')
def main():
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
|
p02726
|
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
class Math():
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def divisor(n):
res = []
i = 1
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
@staticmethod
def round_up(a, b):
return -(-a // b)
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n ** 0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
@staticmethod
def fact(N):
res = {}
tmp = N
for i in range(2, int(N ** 0.5 + 1) + 1):
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
if cnt > 0:
res[i] = cnt
if tmp != 1:
res[tmp] = 1
if res == {}:
res[N] = 1
return res
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
MOD = int(1e09) + 7
INF = int(1e15)
def dist(i, j, X, Y):
if j <= X:
return j - i
if i >= Y:
return j - i
if i <= X < Y <= j:
return X - i + 1 + j - Y
if X <= i < j <= Y:
d1 = j - i
d2 = i - X + 1 + Y - j
return min(d1, d2)
if i <= X <= j <= Y:
d1 = j - i
d2 = X - i + 1 + Y - j
return min(d1, d2)
else:
d1 = j - i
d2 = i - X + 1 + j - Y
return min(d1, d2)
def solve():
N, X, Y = Scanner.map_int()
ans = [0 for _ in range(1, N + 1)]
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
d = dist(i, j, X, Y)
ans[d] += 1
print(*ans[1:], sep='\n')
def main():
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
|
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
class Math():
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def divisor(n):
res = []
i = 1
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
@staticmethod
def round_up(a, b):
return -(-a // b)
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n ** 0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
@staticmethod
def fact(N):
res = {}
tmp = N
for i in range(2, int(N ** 0.5 + 1) + 1):
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
if cnt > 0:
res[i] = cnt
if tmp != 1:
res[tmp] = 1
if res == {}:
res[N] = 1
return res
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
MOD = int(1e09) + 7
INF = int(1e15)
def dist(i, j, X, Y):
a = j - i
b = abs(X - i) + 1 + abs(j - Y)
return min(a, b)
def solve():
N, X, Y = Scanner.map_int()
ans = [0 for _ in range(1, N + 1)]
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
d = dist(i, j, X, Y)
ans[d] += 1
print(*ans[1:], sep='\n')
def main():
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
|
p02726
|
n , x , y = list(map(int,input().split()))
p = [[0 for i in range(j+1)] for j in range(n)]
for i in range(1,n+1):
for j in range(1,i+1):
p[i-1][j-1] = min(abs(i-j),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y))
for i in range(1,n):
ans = 0
for j in range(n):
ans += p[j].count(i)
print(ans)
|
n , x , y = list(map(int,input().split()))
p = [0 for i in range(n)]
for i in range(1,n+1):
for j in range(1,i+1):
p[min(abs(i-j),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y))] += 1
for i in range(1,n):
print((p[i]))
|
p02726
|
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n,x,y = [int(i) for i in readline().split()]
INF = 1001001001
from collections import deque
def push(v,d):
if dist[v] != INF:
return
dist[v] = d
q.append(v)
x -= 1
y -= 1
ans = [0]*n
for sv in range(n):
dist = [INF]*n
q = deque()
push(sv, 0) # 初期状態
while len(q):
v = q.popleft()
d = dist[v]
if v-1 >= 0: push(v-1, d+1)
if v+1 < n: push(v+1, d+1)
if v == x: push(y, d+1)
if v == y: push(x, d+1)
for i in range(n):
ans[dist[i]] += 1
for i in range(n):
ans[i] //= 2 # (1,2)と(2,1)を2度数えてしまっているので2で割る
for i in range(1,n):
print((ans[i]))
|
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n,x,y = [int(i) for i in readline().split()]
ans = [0] * n
for a in range(1, n+1):
for b in range(a+1, n+1):
d = b - a
d2 = abs(x-a) + abs(y-b) + 1
d = d if d < d2 else d2
ans[d] += 1
for i in range(1, n):
print((ans[i]))
|
p02726
|
def dijkstra(s,n,w,cost):
#始点sから各頂点への最短距離
#n:頂点数, w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
d = [float("inf")] * n
used = [False] * n
d[s] = 0
while True:
v = -1
#まだ使われてない頂点の中から最小の距離のものを探す
for i in range(n):
if (not used[i]) and (v == -1):
v = i
elif (not used[i]) and d[i] < d[v]:
v = i
if v == -1:
break
used[v] = True
for j in range(n):
d[j] = min(d[j],d[v]+cost[v][j])
return d
################################
n, x, y = list(map(int,input().split())) #n:頂点数 w:辺の数
w = n
ans = [0 for _ in range(n-1)]
# print(ans)
cost = [[float("inf") for i in range(n)] for i in range(n)]
#cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(w-1):
# x,y = map(int,input().split())
cost[i][i+1] = 1
cost[i+1][i] = 1
cost[x-1][y-1] = 1
cost[y-1][x-1] = 1
# print(dijkstra(0,n,w,cost))
for i in range(n-1):
aa = dijkstra(i, n, w, cost)
# print(aa)
for j in range(i+1, n):
ans[aa[j]] += 1
ans = ans[1:] + [0]
# print(*ans)
for A in ans:
print(A)
|
n, x, y = map(int, input().split())
ans = [0 for _ in range(n-1)]
for i in range(1, n):
for j in range(i+1, n+1):
d = min(j-i, abs(x-i) + abs(y-j) + 1)
ans[d-1] += 1
print(*ans, sep='\n')
|
p02726
|
N, X, Y = list(map(int,input().split()))
X -= 1
Y -= 1
nallpath = N*(N-1)//2
distance = [0] * nallpath
indx = 0
for j in range(N-1):
for i in range(j+1,N):
if i <= X:
distance[indx] = i - j
elif j >= Y:
distance[indx] = i - j
elif j <= X and Y<= i:
distance[indx] = i - j - (Y-X-1)
elif X <= j < i <= Y:
distance[indx] = min(i-j, (j-X)+(Y-i)+1)
elif j <= X and X < i <= Y:
distance[indx] = (X-j) + min(i-X, Y-i+1)
else:
distance[indx] = (i-Y) + min(Y-j, j-X+1)
indx += 1
for i in range(N-1):print((distance.count(i+1)))
|
N, X, Y = list(map(int,input().split()))
X -= 1
Y -= 1
npath = [0] * (N-1)
indx = 0
for j in range(N-1):
for i in range(j+1,N):
if i <= X:
distance = i - j
elif j >= Y:
distance = i - j
elif j <= X and Y<= i:
distance = i - j - (Y-X-1)
elif X <= j < i <= Y:
distance = min(i-j, (j-X)+(Y-i)+1)
elif j <= X and X < i <= Y:
distance = (X-j) + min(i-X, Y-i+1)
else:
distance = (i-Y) + min(Y-j, j-X+1)
npath[distance-1] +=1
for i in range(N-1):print((npath[i]))
|
p02726
|
def main():
from collections import deque
N, X, Y = (int(i) for i in input().split())
X -= 1
Y -= 1
edge = [[] for _ in range(N)]
for i in range(N-1):
edge[i].append(i+1)
edge[i+1].append(i)
edge[X].append(Y)
edge[Y].append(X)
def bfs(s):
d = [-1 for _ in range(N)]
que = deque()
d[s] = 0
que.append(s)
while que:
u = que.popleft()
for v in edge[u]:
if d[v] != -1:
continue
d[v] = d[u] + 1
que.append(v)
return d
dist = [[] for _ in range(N)]
for i in range(N):
dist[i] = bfs(i)
cnt = [0]*N
for i in range(N):
for j in range(i+1, N):
cnt[dist[i][j]] += 1
for c in cnt[1:]:
print(c)
if __name__ == '__main__':
main()
|
def main():
N, X, Y = (int(i) for i in input().split())
cnt = [0]*N
for i in range(1, N+1):
for j in range(i+1, N+1):
d = min(abs(i-j), abs(i-X)+1+abs(j-Y), abs(i-X)+abs(X-Y)+abs(j-Y))
cnt[d] += 1
for d in cnt[1:]:
print(d)
if __name__ == '__main__':
main()
|
p02726
|
from collections import defaultdict
N, X, Y = list(map(int, input().split()))
X -= 1; Y -= 1
pat = defaultdict(int)
for i in range(N):
for j in range(i+1, N):
d = min([abs(i-j), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X)])
pat[d] += 1
for i in range(1, N):
print((pat[i]))
|
N, X, Y = list(map(int, input().split()))
X -= 1; Y -= 1
pat = [0]*(N-1)
for i in range(N):
for j in range(i+1, N):
d = min(abs(i-j), abs(X-i)+1+abs(j-Y))
pat[d-1] += 1
for i in range(N-1):
print((pat[i]))
|
p02726
|
# coding: utf-8
import collections
# 標準入力 <int><int>
N, X, Y = list(map(int, input().split()))
br = []
for i in range(N - 1):
for j in range(i + 1, N):
br.append(min(j - i, abs(X - (i + 1)) + 1 + abs(Y - (j + 1)), abs(Y - (i + 1)) + 1 + abs(X - (j + 1))))
c = collections.Counter(br)
for k, v in list(c.items()):
print(v)
for _ in range(N - 1 - len(c)):
print((0))
|
# coding: utf-8
import collections
# 標準入力 <int><int>
N, X, Y = list(map(int, input().split()))
br = []
for i in range(N - 1):
for j in range(i + 1, N):
"""
#print("(" , i+1, j+1, ")", j-i, abs(X - (i + 1)) + 1 + abs(Y - (j + 1)), abs(Y - (i + 1)) + 1 + abs(X - (j + 1)))
"""
br.append(min(j - i, abs(X - (i + 1)) + 1 + abs(Y - (j + 1)), abs(Y - (i + 1)) + 1 + abs(X - (j + 1))))
c = collections.Counter(br)
for k, v in list(c.items()):
print(v)
for _ in range(N - 1 - len(c)):
print((0))
|
p02726
|
n,x,y=list(map(int,input().split()))
#a<b
def dis(a,b):
return min (b-a,abs(a-x)+1+abs(b-y))
for k in range(1,n):
count=0
#i<j
for i in range(1,n):
for j in range(i+1,n+1):
if dis(i,j)==k:
count+=1
print(count)
|
n,x,y=map(int,input().split())
#a<b
def dis(a,b):
return min (b-a,abs(a-x)+1+abs(b-y))
# for k in range(1,n):
# count=0
# #i<j
# for i in range(1,n):
# for j in range(i+1,n+1):
# if dis(i,j)==k:
# count+=1
# print(count)
ans=[0]*(n-1)
#i<j
for i in range(1,n):
for j in range(i+1,n+1):
ans[dis(i,j)-1]+=1
print(*ans,sep="\n")
|
p02726
|
n,x,y=map(int,input().split())
#a<b
def dis(a,b):
return min (b-a,abs(a-x)+1+abs(b-y))
# for k in range(1,n):
# count=0
# #i<j
# for i in range(1,n):
# for j in range(i+1,n+1):
# if dis(i,j)==k:
# count+=1
# print(count)
ans=[0]*(n-1)
#i<j
for i in range(1,n):
for j in range(i+1,n+1):
ans[dis(i,j)-1]+=1
print(*ans,sep="\n")
|
n,x,y=list(map(int,input().split()))
#a<b
def dis(a,b):
return min (b-a,abs(a-x)+1+abs(b-y))
# for k in range(1,n):
# count=0
# #i<j
# for i in range(1,n):
# for j in range(i+1,n+1):
# if dis(i,j)==k:
# count+=1
# print(count)
ans=[0]*(n-1)
#i<j
for i in range(1,n):
for j in range(i+1,n+1):
ans[dis(i,j)-1]+=1
#print(*ans,sep="\n")
print(("\n".join(map(str,ans))))
|
p02726
|
N, X, Y = list(map(int, input().split()))
dp = [[N+10] * N for i in range(N)]
for i in range(N-1):
dp[i][i+1] = 1
for i in range(1, N):
dp[i][i-1] = 1
dp[X-1][Y-1] = 1
dp[Y-1][X-1] = 1
for k in range(N):
for i in range(N):
for j in range(N):
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
mindcnt = {}
for i in range(N):
mindcnt[i] = 0
for i in range(N):
for j in range(i+1, N):
mind = dp[i][j]
mindcnt[mind] += 1
for k in range(1, N):
print((mindcnt[k]))
|
N, X, Y = list(map(int, input().split()))
mind = [[N] * N for i in range(N)]
for i in range(N):
for j in range(i+1, N):
mind[i][j] = min(abs(j-i), abs((X-1)-i)+1+abs(j-(Y-1)), abs((Y-1)-i)+1+abs(j-(X-1)))
mindcnt = [0] * N
for i in range(N):
for j in range(i+1, N):
d = mind[i][j]
mindcnt[d] += 1
for k in range(1, N):
print((mindcnt[k]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
dic = {}
def Warshall_Floyd(N):
for k in range(N):
for i in range(N):
for j in range(N):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d
d = [[float("inf")] * N for i in range(N)]
for i in range(N-1):
d[i][i + 1] = 1
d[i + 1][i] = 1
for i in range(N):
d[i][i] = 0
d[X-1][Y-1] = 1
d[Y-1][X-1] = 1
d = Warshall_Floyd(N)
for i in range(N):
for j in range(N):
if dic.get(d[i][j]) is None:
dic[d[i][j]] = 1
else:
dic[d[i][j]] += 1
for i in range(1, N):
if dic.get(i) is None:
print((0))
else:
print((dic[i]//2))
|
N, X, Y = list(map(int, input().split()))
d = {}
for i in range(1, N):
for j in range(i+1, N+1):
m = min(j-i, abs(X-i) + 1 + abs(Y-j))
if d.get(m) is None:
d[m] = 1
else:
d[m] += 1
for i in range(1, N):
if d.get(i) is None:
print((0))
else:
print((d[i]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
dist_list = []*N
for i in range(N):
for j in range(i+1, N):
a = j - i
b = abs(i+1 - X) + abs(j+1 -Y) + 1
if a > b:
dist_list.append(b)
else:
dist_list.append(a)
for k in range(N-1):
print((dist_list.count(k+1)))
|
N, X, Y = list(map(int, input().split()))
dist_list = [0]*N
for i in range(N-1):
for j in range(i+1, N):
a = j - i
b = abs(i+1 - X) + abs(j+1 -Y) + 1
dist_list[min(a,b)] += 1
for k in range(N-1):
print((dist_list[k+1]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
dist = [0]*N
for i in range(N):
for k in range(i,N):
if i == X - 1 and k == Y - 1:
dist[1] += 1
continue
if X - 1 <= k <= Y - 1 and i <= X - 1:
tmp = min(k-i,(X-1)-i+1+(Y-1-k))
dist[tmp] += 1
continue
if X - 1 < i < Y - 1 and k >= Y - 1:
tmp = min(k-i,i-(X-1)+1+k-(Y-1))
dist[tmp] += 1
continue
if X - 1 <= k <= Y - 1 and X - 1 <= i <= Y - 1:
tmp = min(k-i,i-(X-1)+1+(Y-1-k))
dist[tmp] += 1
continue
if i <= X - 1 and k >= Y - 1:
dist[k-i-(Y-X-1)] += 1
continue
dist[k-i] += 1
for i in range(1,N):
print((dist[i]))
|
N, X, Y = list(map(int, input().split()))
dist = [0]*N
for i in range(N):
for k in range(i+1,N):
if i == X - 1 and k == Y - 1:
dist[1] += 1
continue
if X - 1 <= k <= Y - 1 and i <= X - 1:
tmp = min(k-i,(X-1)-i+1+(Y-1-k))
dist[tmp] += 1
continue
if X - 1 < i < Y - 1 and k >= Y - 1:
tmp = min(k-i,i-(X-1)+1+k-(Y-1))
dist[tmp] += 1
continue
if X - 1 <= k <= Y - 1 and X - 1 <= i <= Y - 1:
tmp = min(k-i,i-(X-1)+1+(Y-1-k))
dist[tmp] += 1
continue
if i <= X - 1 and k >= Y - 1:
dist[k-i-(Y-X-1)] += 1
continue
dist[k-i] += 1
for i in range(1,N):
print((dist[i]))
|
p02726
|
N,X,Y = list(map(int,input().split()))
D = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
for j in range(i,N):
D[i][j] = j-i
D[X-1][Y-1] = 1
for i in range(N):
for j in range(i,N):
c,d = max(i,X-1),min(i,X-1)
e,f = max(Y-1,j),min(j,Y-1)
a = min(D[i][j],D[d][c]+D[f][e]+1)
D[i][j] = a
A = [0]*(N-1)
for i in range(N):
for j in range(i,N):
k = D[i][j]
if k == 0:
continue
A[k-1] += 1
for a in A:
print(a)
|
N,X,Y = list(map(int,input().split()))
D = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
for j in range(i+1,N):
D[i][j] = j-i
D[X-1][Y-1] = 1
A = [0]*(N-1)
for i in range(N):
for j in range(i+1,N):
c,d = max(i,X-1),min(i,X-1)
e,f = max(Y-1,j),min(j,Y-1)
a = min(D[i][j-1]+1,D[d][c]+D[f][e]+1)
D[i][j] = a
if a == 0:
continue
A[a-1] += 1
for a in A:
print(a)
|
p02726
|
import collections
N, X, Y = list(map(int, input().split()))
x = X-1
y = Y-1
dist = dict()
for i in range(N-1):
for j in range(i+1, N):
dist_ = min(abs(j-i), abs(x-i) + 1 + abs(j-y), abs(y-i) +1 + abs(j - x))
dist[i, j] = dist_
out = collections.Counter(list(dist.values()))
for i in range(N-1):
print((out[i+1]))
|
N, X, Y = list(map(int, input().split()))
x = X-1
y = Y-1
dist = [0] * N
for i in range(N-1):
for j in range(i+1, N):
dist_ = min(abs(j-i), abs(x-i) + 1 + abs(j-y), abs(y-i) +1 + abs(j - x))
dist[dist_] += 1
for i in range(N-1):
print((dist[i+1]))
|
p02726
|
N, X, Y = list(map(int, input().split(' ')))
X -= 1
Y -= 1
dist_map = {}
def search(origin):
dist = []
# X, Yの辺がない場合
for i in range(N):
dist.append(abs(origin - i))
# X, Yの辺がある場合
if dist[X] < dist[Y]:
dist[Y] = dist[X] + 1
elif dist[Y] < dist[X]:
dist[X] = dist[Y] + 1
for i in range(N):
if i - 1 >= 0:
dist[i] = min(dist[i], dist[i-1]+1)
if i + 1 < N:
dist[i] = min(dist[i], dist[i+1]+1)
for i in reversed(list(range(N))):
if i - 1 >= 0:
dist[i] = min(dist[i], dist[i-1]+1)
if i + 1 < N:
dist[i] = min(dist[i], dist[i+1]+1)
#print(*dist)
return dist
for i in range(N):
dist_map[i] = search(i)
#print(N)
count = [0 for i in range(N)]
for i in range(N):
#print('i='+str(i))
#dist = dist_map[i]
#print(*dist)
dist = dist_map[i]
for dis in dist:
count[dis] += 1
for i in range(1, N):
print((count[i]//2))
|
N, X, Y = list(map(int, input().split(' ')))
X -= 1
Y -= 1
dist_map = {}
def search(origin):
dist = []
# X, Yの辺がない場合
for i in range(N):
dist.append(abs(origin - i))
# X, Yの辺がある場合
if dist[X] < dist[Y]:
dist[Y] = dist[X] + 1
elif dist[Y] < dist[X]:
dist[X] = dist[Y] + 1
for i in range(N):
if i - 1 >= 0:
dist[i] = min(dist[i], dist[i-1]+1)
if i + 1 < N:
dist[i] = min(dist[i], dist[i+1]+1)
for i in reversed(list(range(N))):
if i - 1 >= 0:
dist[i] = min(dist[i], dist[i-1]+1)
if i + 1 < N:
dist[i] = min(dist[i], dist[i+1]+1)
#print(*dist)
return dist
count = [0 for i in range(N)]
for i in range(N):
dist = search(i)
for dis in dist:
count[dis] += 1
for i in range(1, N):
print((count[i]//2))
|
p02726
|
N,X,Y = list(map(int,input().split()))
li = [0]*(N-1)
for i in range(0,N-1):
for j in range(i+1,N):
dis = min(j-i,abs(j-(X-1))+1+abs(i-(Y-1)),abs(i-(X-1))+1+abs(j-(Y-1)))
li[dis-1] += 1
for ans in li:
print(ans)
|
N,X,Y = list(map(int,input().split()))
li = [0]*(N-1)
for i in range(0,N-1):
for j in range(i+1,N):
dis = min(j-i,abs(i-(X-1))+1+abs(j-(Y-1)))
li[dis-1] += 1
for ans in li:
print(ans)
|
p02726
|
N,X,Y = list(map(int,input().split(' ')))
ls = {}
for i in range(1,N):
for j in range(i+1,N+1):
l = min(abs(j-i),abs(i-X)+1+abs(j-Y),abs(i-Y)+1+abs(j-X))
if l not in list(ls.keys()):
ls[l] = 1
else:
ls[l] = ls[l] + 1
for i,(k,v) in enumerate(sorted(list(ls.items()),key=lambda x:x[0])):
print(v)
for j in range(i+2,N):
print((0))
|
N,X,Y = list(map(int,input().split(' ')))
ls = [0 for i in range(N-1)]
for i in range(1,N):
for j in range(i+1,N+1):
l = min(j-i,abs(i-X)+1+abs(j-Y))
ls[l-1] = ls[l-1] + 1
for i in range(N-1):
print((ls[i]))
|
p02726
|
from collections import deque
if __name__ == '__main__':
n, x, y = list(map(int, input().split()))
ans = [0] * (n+1)
g = [[i+1, i-1] for i in range(n+1)]
g[0].clear()
g[1].pop(1)
g[n].pop(0)
g[x].append(y)
g[y].append(x)
for i in range(1,n+1):
q = deque()
time = 0
visit = [False] * (n+1)
q.append((i, time))
while(len(q) > 0):
item = q.popleft()
if visit[item[0]] == False:
visit[item[0]] = True
ans[item[1]] += 1
for k in g[item[0]]:
q.append((k, item[1]+1))
for i in range(1,n):
print((ans[i]//2))
|
from collections import deque
n, x, y = list(map(int, input().split()))
ans = [0] * (n+1)
g = [[i+1, i-1] for i in range(n+1)]
#g[0].clear() pypyにclearなし
g[1].pop(1)
g[n].pop(0)
g[x].append(y)
g[y].append(x)
for i in range(1,n+1):
q = deque()
time = 0
visit = [False] * (n+1)
q.append((i, time))
while(len(q) > 0):
item = q.popleft()
if visit[item[0]] == False:
visit[item[0]] = True
ans[item[1]] += 1
for k in g[item[0]]:
q.append((k, item[1]+1))
for i in range(1,n):
print((ans[i]//2))
|
p02726
|
def main():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
answer = [0 for i in range(N+1)]
for i in range(0, N):
for j in range(i+1, N):
answer[min(abs(j-i), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X))] += 1
for i in range(1, N):
print((answer[i]))
if __name__ == '__main__':
main()
|
def main():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
answer = [0 for i in range(N+1)]
for i in range(0, N):
for j in range(i+1, N):
answer[min(abs(j-i), abs(X-i)+1+abs(j-Y))] += 1
for i in range(1, N):
print((answer[i]))
if __name__ == '__main__':
main()
|
p02726
|
N,X,Y=list(map(int,input().split()))
L=[]
for i in range(1,N):
for j in range(i+1,N+1):
l=min(j-i,abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X))
L.append(l)
for i in range(1,N):
print((L.count(i)))
|
N,X,Y=list(map(int,input().split()))
L=[0]*(N)
for i in range(1,N):
for j in range(i+1,N+1):
l=min(j-i,abs(X-i)+1+abs(j-Y))
L[l]+=1
for i in range(1,N):
print((L[i]))
|
p02726
|
from collections import deque
def bfs(start, end):
Q = deque()
Q.append(start)
dist[start] = 0
while Q:
v = Q.popleft()
for nv in G[v]:
if dist[nv] != -1:
continue
Q.append(nv)
dist[nv] = dist[v] + 1
if nv == end:
return dist[nv]
N, X, Y = list(map(int, input().split()))
G = [[] for _ in range(N)]
res = [0] * N
for i in range(N - 1):
G[i].append(i + 1)
G[i + 1].append(i)
if abs(X - Y) != 1:
G[X - 1].append(Y - 1)
G[Y - 1].append(X - 1)
for i in range(N - 1):
for j in range(i + 1, N):
dist = [-1] * N
res[bfs(i, j)] += 1
for i in range(1, N):
print((res[i]))
|
N,X,Y=list(map(int,input().split()))
ans=[0 for i in range(1,N)]
for i in range(1,N):
for j in range(i+1,N+1):
k=min(abs(j-i),abs(X-i)+1+abs(Y-j),abs(Y-i)+1+abs(X-j))
ans[k-1]+=1
for i in ans:
print(i)
|
p02726
|
n, x, y = list(map(int, input().split()))
ans = [0] * n
for i in range(1, n):
for j in range(i + 1, n + 1):
if i < x:
if j < x:
d = j - i
elif x <= j <= y:
d = min(j - i, y - j + x - i + 1)
else:
d = j - y + x - i + 1
elif x <= i <= y:
if j <= y:
d = min(j - i, y - j + i - x + 1)
else:
d = min(j - i, j - y + i - x + 1)
else:
d = j - i
ans[d] += 1
print(('\n'.join(map(str, ans[1:]))))
|
n, x, y = list(map(int, input().split()))
ans = [0] * n
for i in range(1, n):
for j in range(i + 1, n + 1):
ans[min(j - i, abs(i - x) + abs(j - y) + 1)] += 1
print(('\n'.join(map(str, ans[1:]))))
|
p02726
|
N,X,Y = list(map(int,input().split()))
Alist = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
for j in range(i,N):
Alist[i][j] = j-i
Alist[X-1][Y-1] = 1
for i in range(N):
for j in range(i,N):
Alist[i][j] = min(Alist[i][j],abs(X-1-i)+abs(Y-1-j)+1)
p = [0 for i in range(N)]
for i in range(N):
for j in range(i,N):
k = Alist[i][j]
p[k] = p[k] + 1
for s in range(1,N):
print((p[s]))
|
N,X,Y = list(map(int,input().split()))
Alist = [[0 for i in range(N)] for j in range(N)]
p = [0 for i in range(N)]
for i in range(N):
for j in range(i,N):
k = min(j-i,abs(X-1-i)+abs(Y-1-j)+1)
p[k] = p[k] + 1
for s in range(1,N):
print((p[s]))
|
p02726
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
n,x,y = i_l()
x -= 1
y -= 1
a = []
for i in range(n):
for j in range(i+1, n):
a.append(min(abs(i-j), abs(x-i)+1+abs(y-j), abs(y-j)+1+abs(y-i)))
for i in range(1, n):
count = a.count(i)
if count>0:
print(count)
else:
print((0))
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
n,x,y = i_l()
x -= 1
y -= 1
a = [0]*n
for i in range(n):
for j in range(i+1, n):
b = min(abs(i-j), abs(x-i)+1+abs(y-j), abs(y-j)+1+abs(y-i))
a[b] += 1
for i in a[1:]:
print(i)
|
p02726
|
import collections
import heapq
class Dijkstra():
def __init__(self):
self.e = collections.defaultdict(list)
def add(self, u, v, d, directed=False):
"""
#0-indexedでなくてもよいことに注意
#u = from, v = to, d = cost
#directed = Trueなら、有向グラフである
"""
if directed is False:
self.e[u].append([v, d])
self.e[v].append([u, d])
else:
self.e[u].append([v, d])
def delete(self, u, v):
self.e[u] = [_ for _ in self.e[u] if _[0] != v]
self.e[v] = [_ for _ in self.e[v] if _[0] != u]
def search(self, s):
"""
#0-indexedでなくてもよいことに注意
#:param s: 始点
#:return: 始点から各点までの最短経路と最短経路を求めるのに必要なprev
"""
d = collections.defaultdict(lambda: float('inf'))
prev = collections.defaultdict(lambda: None)
d[s] = 0
q = []
heapq.heappush(q, (0, s))
v = collections.defaultdict(bool)
while len(q):
k, u = heapq.heappop(q)
if v[u]:
continue
v[u] = True
for uv, ud in self.e[u]:
if v[uv]:
continue
vd = k + ud
if d[uv] > vd:
d[uv] = vd
prev[uv] = u
heapq.heappush(q, (vd, uv))
return d
def getDijkstraShortestPath(self, start, goal):
_, prev = self.Dijkstra_search(start)
shortestPath = []
node = goal
while node is not None:
shortestPath.append(node)
node = prev[node]
return shortestPath[::-1]
n, x, y = list(map(int,input().split()))
ans = collections.defaultdict(int)
edges = [[i, i+1, 1] for i in range(1, n)]
edges += [[x, y, 1]]
graph1 = Dijkstra()
for u, v, a in edges:
graph1.add(u,v,a)
for i in range(1,n+1):
result_a = graph1.search(i)
for j in range(i+1, n+1):
ans[result_a[j]] += 1
for i in range(1,n-1):
print((ans[i]))
print((0))
|
n, x, y = list(map(int,input().split()))
ans = [0] * (n+10)
for i in range(1, n+1):
for j in range(i+1, n+1):
distance = min(abs(j-i), abs(x-i) + 1 + abs(y-j), abs(y-i) + 1 + abs(x-j))
ans[distance] += 1
for i in range(1, n):
print((ans[i]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
t = [0] * (N - 1)
for i in range(1, N):
for j in range(i + 1, N + 1):
t[min(j - i, abs(X - i) + 1 + abs(Y - j)) - 1] += 1
print(('\n'.join(map(str, t))))
|
N, X, Y = list(map(int, input().split()))
t = [0] * (N - 1)
for i in range(1, N):
for j in range(i + 1, N + 1):
t[min(j - i, abs(X - i) + 1 + abs(Y - j)) - 1] += 1
print(('\n'.join(map(str, t))))
#print(*result, sep='\n')
|
p02726
|
n,x,y=[int(j) for j in input().split()]
l=[[0]*n for i in range(n)]
ans=[0]*n
x-=1
y-=1
s=y-x-1
for i in range(n):
for j in range(n):
if i<j:
ans[min(j-i,abs(i-x)+abs(j-y)+1,)]+=1
print(('\n'.join(map(str,ans[1:]))))
|
n,x,y=[int(j) for j in input().split()]
ans=[0]*n
for i in range(1,1+n):
for j in range(i+1,1+n):
t=min(j-i,abs(x-i)+abs(y-j)+1)
ans[t]+=1
print(('\n'.join(map(str,ans[1:]))))
|
p02726
|
N, X, Y = list(map(int, input().split(' ')))
res = [0] * (N)
for i in range(N):
for j in range(i+1, N):
dist = min(abs(i - j), abs(i - X + 1) + 1 + abs(j - Y + 1), abs(i-Y+1) + 1 + abs(j-X+1))
res[dist] += 1
for i in range(1, N):
print((res[i]))
|
N, X, Y = list(map(int, input().split(' ')))
res = [0] * (N)
for i in range(N):
for j in range(i+1, N):
dist = min(abs(i - j), abs(i - X + 1) + 1 + abs(j - Y + 1))
res[dist] += 1
for i in range(1, N):
print((res[i]))
|
p02726
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans = [0] * n
for i in range(n):
for j in range(i+1, n):
if i <= x and y <= j:
dist = j - i - (y - x) + 1
else:
dist = min(j - i, abs(i-x) + abs(j-y) + 1)
ans[dist] += 1
for i in range(1,n):
print((ans[i]))
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans = [0] * n
for i in range(n):
for j in range(i+1, n):
dist = min(j - i, abs(i-x) + abs(j-y) + 1)
ans[dist] += 1
for i in range(1,n):
print((ans[i]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
ans = [0] * (N - 1)
for i in range(N):
for j in range(i + 1, N):
dist = min(abs(i - j), abs((X - 1) - i) + abs((Y - 1) - j) + 1, abs((Y - 1) - i) + abs((X - 1) - j) + 1)
ans[dist - 1] += 1
# print("i:{}, j:{}, dist:{}".format(i, j, dist))
for k in ans:
print(k)
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
ans = [0] * (N - 1)
for i in range(N):
for j in range(i + 1, N):
dist = min(abs(i - j), abs(X - i) + abs(Y - j) + 1, abs(Y - i) + abs(X - j) + 1)
ans[dist - 1] += 1
# print("i:{}, j:{}, dist:{}".format(i, j, dist))
for k in ans:
print(k)
|
p02726
|
from collections import Counter
N,X,Y = list(map(int, input().split()))
X -= 1
Y -= 1
L = []
for i in range(N-1):
for j in range(i+1,N):
L.append(min(abs(i-j),abs(X-i)+abs(Y-j)+1,abs(Y-i)+abs(X-j)+1))
D = Counter(L)
for k in range(1,N):
print((D[k]))
|
N,X,Y = map(int, input().split())
D = [0] * N
for i in range(1,N):
for j in range(i+1,N+1):
D[min(abs(i-j),abs(X-i)+abs(Y-j)+1,abs(Y-i)+abs(X-j)+1)] += 1
print (*D[1:], sep="\n")
|
p02726
|
N,X,Y = map(int, input().split())
D = [0] * N
for i in range(1,N):
for j in range(i+1,N+1):
D[min(abs(i-j),abs(X-i)+abs(Y-j)+1,abs(Y-i)+abs(X-j)+1)] += 1
print (*D[1:], sep="\n")
|
N,X,Y = map(int, input().split())
D = [0] * N
for i in range(1,N):
for j in range(i+1,N+1):
D[min(abs(i-j),abs(X-i)+abs(Y-j)+1)] += 1
print (*D[1:], sep="\n")
|
p02726
|
N, X, Y = list(map(int, input().split()))
ans = [0] * (N - 1)
for i in range(1, N + 1, 1):
for j in range(i + 1, N + 1, 1):
tmp = min(
abs(j - i),
abs(X - i) + 1 + abs(j - Y),
abs(X - j) + 1 + abs(i - Y) # このパターンは
)
ans[tmp - 1] += 1
for a in ans:
print(a)
|
N, X, Y = list(map(int, input().split()))
ans = [0] * (N - 1)
for i in range(1, N + 1, 1):
for j in range(i + 1, N + 1, 1):
tmp = min(
abs(j - i),
abs(X - i) + 1 + abs(j - Y)
)
ans[tmp - 1] += 1
for a in ans:
print(a)
|
p02726
|
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
import itertools
#import bisect
import copy
from functools import lru_cache
def sosuhante(n):
for k in range(2, int(math.sqrt(n))+1):
if n% k ==0:
return False
return True
def cmb(n, r):
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
def kingaku(a,b,n):
keta=len(str(n))
return a*n+b*keta
def my_index(l, x, default=False):
if x in l:
return l.index(x)
else:
return default
# h,w,a,b = map(int, input().split())
# c = [[0 for j in range(n)] for i in range(n)]
def ret(a):
c=[None]*(len(a)-1)
if len(a)==1:
return a[0]
elif len(a)==0:
return 0
for i in range(1,len(a)):
c[i-1]=abs(a[i]-a[i-1])
return ret(c)
def main():
n,x,y=list(map(int,input().split()))
d2=[[INFI for i in range(n+1)] for j in range(n+1)]
total=[0]*(n+1)
d2[x][y]=1
d2[y][x]=1
for i in range(1,n+1):
for j in range(1,n+1):
d2[i][j]=min(d2[i][j],abs(i-j))
for k in range(1,n+1):
for i in range(1,n+1):
for j in range(1,n+1):
d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
for i in range(1,n+1):
for j in range(1,n+1):
total[d2[i][j]]+=1
for i in range(1,n):
print((total[i]//2))
if __name__ == "__main__":
main()
|
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
import itertools
#import bisect
import copy
from functools import lru_cache
def sosuhante(n):
for k in range(2, int(math.sqrt(n))+1):
if n% k ==0:
return False
return True
def cmb(n, r):
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
def kingaku(a,b,n):
keta=len(str(n))
return a*n+b*keta
def my_index(l, x, default=False):
if x in l:
return l.index(x)
else:
return default
# h,w,a,b = map(int, input().split())
# c = [[0 for j in range(n)] for i in range(n)]
def ret(a):
c=[None]*(len(a)-1)
if len(a)==1:
return a[0]
elif len(a)==0:
return 0
for i in range(1,len(a)):
c[i-1]=abs(a[i]-a[i-1])
return ret(c)
def main():
n,x,y=list(map(int,input().split()))
d2=[[INFI for i in range(n+1)] for j in range(n+1)]
total=[0]*(n+1)
d2[x][y]=1
d2[y][x]=1
for i in range(1,n+1):
for j in range(1,n+1):
d2[i][j]=min(d2[i][j],abs(i-j),d2[i][x]+d2[y][j]+1,abs(d2[i][y]+d2[x][j]+1))
for i in range(1,n+1):
for j in range(1,n+1):
d2[i][j]=min(d2[i][j],abs(i-j),d2[i][x]+d2[y][j]+1,abs(d2[i][y]+d2[x][j]+1))
for i in range(1,n+1):
for j in range(1,n+1):
total[d2[i][j]]+=1
for i in range(1,n):
print((total[i]//2))
if __name__ == "__main__":
main()
|
p02726
|
# coding: utf-8
N, X, Y = list(map(int, input().split()))
list = []
for i in range(1,N):
for j in range(i+1,N+1):
list.append(min(j-i, abs(X-i)+1+abs(Y-j)))
for k in range(1,N):
print((list.count(k)))
|
# coding: utf-8
N, X, Y = list(map(int, input().split()))
ans = [0]*N
for i in range(1,N):
for j in range(i+1,N+1):
l = min(j-i, abs(X-i)+1+abs(Y-j))
ans[l] += 1
for k in range(1,N):
print((ans[k]))
|
p02726
|
import sys
input = sys.stdin.buffer.readline
from itertools import chain
from collections import Counter
def floyd_warshall(V, dist): # 動的計画法。頂点 k まで経由することが可能な場合の最短距離という部分問題を考えて、k = 0 から漸化式的に計算する
for k in range(V):
for i in range(V):
for j in range(V):
if dist[i][j] > dist[i][k] + dist[k][j]:
dist[i][j] = dist[i][k] + dist[k][j] # dist は頂点 k までを経由した場合の最短距離。dist[i][k]は k を経由することは無いので、dist[i][k]は k ステップ目で更新されることはない。
# よって、min の中身は全て k-1 ステップ目の情報で構成されており、漸化式となっている。
return dist
##############################
V, X, Y = list(map(int, input().split())) # V:頂点数 E:辺の数
INF = float("inf") # 10**18 にすると、負のコストがある場合に少し面倒になる
dist = [[INF] * V for _ in range(V)] # 辺が存在しない事をコスト無限大で表現
for k in range(V-1):
i,j,weight = k, k+1, 1
# i -= 1 # 番号のデクリメントが必要な場合、コメントアウトを消す
# j -= 1
dist[i][j] = weight
dist[j][i] = weight # 無向グラフの場合はコメントアウトを消す
for i in range(V):
dist[i][i] = 0 # 自身のところに行くコストは0
dist[X-1][Y-1] = 1
dist[Y-1][X-1] = 1
d = floyd_warshall(V, dist) # 各点間の距離が隣接行列の形で与えられる
res = Counter(chain.from_iterable(d))
for i in range(1,V):
print((res.get(i,0)//2))
|
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
dist = [0]*(N-1)
for i in range(N):
for j in range(i+1, N):
dist[min(j-i, abs(X-i) + 1 + abs(Y-j))-1] += 1
print(*dist, sep="\n")
|
p02726
|
def main():
import sys
input = sys.stdin.readline
from collections import deque
n,x,y = list(map(int,input().split()))
ans = [0]*(n)
E = [[] for i in range(n)]
E[0].append(1)
E[n-1].append(n-2)
for i in range(1,n-1):
E[i].append(i-1)
E[i].append(i+1)
E[x-1].append(y-1)
E[y-1].append(x-1)
ans = [0]*(n)
def search(x):
d = [float("INF")]*n
d[x] = 0
q = deque([])
q.append((x,0))
while q:
bef,l = q.pop()
for nex in E[bef]:
if d[nex] > l+1:
d[nex] = l+1
q.append((nex,l+1))
d = d[x:]
for j in range(n):
ans[j] += d.count(j)
for i in range(n-1):
search(i)
for i in ans[1:]:
print(i)
if __name__ == "__main__":
main()
|
n,x,y = list(map(int,input().split()))
ans = [0]*(n)
for i in range(1,n):
for j in range(i+1,n+1):
d = min(j-i,abs(x-i)+abs(y-j)+1)
ans[d] += 1
for i in ans[1:]:
print(i)
|
p02726
|
from heapq import *
from collections import Counter
import itertools
n, x, y = list(map(int,input().split()))
edges = [[] for _ in range(n)]
def dijkstra(s, edges):
d = [float('inf')] * n
d[s] = 0
heap = [(0, s)]
while heap:
c, node = heappop(heap)
for cost, v in edges[node]:
if c + cost < d[v]:
d[v] = c + cost
heappush(heap, (d[v], v))
return d
for i in range(n-1):
u, v = i, i+1
edges[u].append([1,v])
edges[v].append([1,u])
edges[x-1].append([1, y-1])
edges[y-1].append([1, x-1])
ans = []
for s in range(n):
ans.append(dijkstra(s, edges))
f_ans = []
for i in range(n):
f_ans.append(ans[i][i+1:])
f_ans = list(itertools.chain.from_iterable(f_ans))
f_ans = Counter(f_ans)
for i in range(1, n):
print((f_ans[i]))
|
from heapq import *
from collections import Counter
import itertools
n, x, y = list(map(int,input().split()))
edges = [[] for _ in range(n)]
def dijkstra(s, edges):
d = [float('inf')] * n
d[s] = 0
heap = [(0, s)]
while heap:
c, node = heappop(heap)
for cost, v in edges[node]:
if c + cost < d[v]:
d[v] = c + cost
heappush(heap, (d[v], v))
return d
for i in range(n-1):
u, v = i, i+1
edges[u].append([1,v])
edges[v].append([1,u])
edges[x-1].append([1, y-1])
edges[y-1].append([1, x-1])
ans = []
for s in range(n):
ans.append(dijkstra(s, edges))
f_ans = []
for i in range(n):
f_ans.append(ans[i][i+1:])
f_ans = Counter(list(itertools.chain.from_iterable(f_ans)))
for i in range(1, n):
print((f_ans[i]))
|
p02726
|
from collections import Counter
def flatten(array):
return [item for sublist in array for item in sublist]
n, x, y = list(map(int, input().split()))
c = [[10**4]*n for i in range(n)]
for i in range(n):
c[i-1][i] = 1
c[i][i-1] = 1
c[-1][0] = 10**4
c[0][-1] = 10**4
c[x-1][y-1] = 1
c[y-1][x-1] = 1
for k in range(n):
for i in range(n):
for j in range(n):
c[i][j]=min(c[i][j],c[i][k]+c[k][j])
c[j][j]=0
p = sorted(list(Counter(flatten(c)).items()), key=lambda x: x[0])[1:]
t = 0
for _, cnt in p:
print((cnt // 2))
for _ in range(n-1-len(p)):
print((0))
|
#!/usr/bin/env python3
n, x, y = map(int, input().split())
a = abs
d = [0] * n
for i in range(1, n+1):
for j in range(i + 1, n+1):
d[min(j-i, a(x-i)+a(y-j)+1, a(x-j)+a(y-i)+1)] += 1
print(*d[1:], sep="\n")
|
p02726
|
from collections import deque
def count_pair(k):
cnt = 0
for i in range(1, N+1):
visited = [-1]*(N+1)
visited[i] = 0
s = 0
q = deque([[i]])
while s != k:
p = []
A = q.popleft()
for a in A:
if a == X and visited[Y] == -1:
p.append(Y)
visited[Y] = 0
if a == Y and visited[X] == -1:
p.append(X)
visited[X] = 0
if a+1 <=N and visited[a+1] == -1:
p.append(a+1)
visited[a+1] = 0
if a-1 >= 1 and visited[a-1] == -1:
p.append(a-1)
visited[a-1] = 0
q.append(p)
s += 1
r = q[0]
t = 0
for j in range(len(r)):
if r[j] > i:
t += 1
cnt += t
return cnt
N, X, Y = list(map(int, input().split()))
for k in range(1, N):
print((count_pair(k)))
|
N, X, Y = list(map(int, input().split()))
t = [0]*N
for i in range(1, N):
for j in range(i+1, N+1):
t[min(j-i, abs(X-i)+1+abs(j-Y))] += 1
for k in range(1, N):
print((t[k]))
|
p02726
|
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return list(map(int, sys.stdin.readline().split()))
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
#input = sys.stdin.readline
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return list(map(int, sys.stdin.readline().split()))
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
#input = sys.stdin.readline
from collections import deque
N,X,Y=MI()
l = []
for i in range(N):
if i!=0 and i!=N-1:
n = [i-1,i+1]
elif i==0:
n = [1]
else:
n = [N-2]
if i==X-1:
n += [Y-1]
if i==Y-1:
n += [X-1]
l.append(n)
ans = []
for i in range(N):
dist = [-1]*N
q=deque()
q.append(i)
dist[i]=0
while q:
u = q.popleft()
for next in l[u]:
if dist[next]==-1:
dist[next]=dist[u]+1
q.append(next)
ans += dist
for k in range(N-1):
print(((ans.count(k+1))//2))
|
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
#input = sys.stdin.readline
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
#input = sys.stdin.readline
from collections import deque
N,X,Y=MI()
l = []
for i in range(N):
if i!=0 and i!=N-1:
n = [i-1,i+1]
elif i==0:
n = [1]
else:
n = [N-2]
if i==X-1:
n += [Y-1]
if i==Y-1:
n += [X-1]
l.append(n)
ans = [0]*(N-1)
for i in range(N):
dist = [-1]*N
q=deque()
q.append(i)
dist[i]=0
while q:
u = q.popleft()
for next in l[u]:
if dist[next]==-1:
dist[next]=dist[u]+1
ans[dist[u]] += 1
q.append(next)
[print(x//2) for x in ans]
|
p02726
|
#!/usr/bin/python3
(n, x, y) = list(map(int, input().split()))
cs = [0 for i in range(n)]
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
d = min(abs(j - i), abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x))
if d == (abs(y - i) + 1 + abs(j - x)):
print((i, j, d))
cs[d] += 1
for i in range(1, n):
print((cs[i]))
|
#!/usr/bin/python3
(n, x, y) = list(map(int, input().split()))
cs = [0 for i in range(n)]
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
d = min(abs(j - i), abs(x - i) + 1 + abs(j - y))
cs[d] += 1
for i in range(1, n):
print((cs[i]))
|
p02726
|
#!/usr/bin/python3
(n, x, y) = list(map(int, input().split()))
cs = [0 for i in range(n)]
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
d = min(abs(j - i), abs(x - i) + 1 + abs(j - y))
cs[d] += 1
for i in range(1, n):
print((cs[i]))
|
(n, x, y) = list(map(int, input().split()))
cs = [0 for i in range(n)]
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
d = min(abs(j - i), abs(x - i) + 1 + abs(j - y))
cs[d] += 1
for i in range(1, n):
print((cs[i]))
|
p02726
|
from sys import stdin
def main():
n, x, y = map(int, stdin.readline().split())
x -= 1
y -= 1
summary = [0] * (n - 1)
for i in range(n):
for j in range(i + 1, n):
d = min(j - i, abs(i - x) + abs(j - y) + 1, abs(i - y) + abs(j - x) + 1)
summary[d - 1] += 1
print(*summary, sep='\n')
if __name__ == "__main__":
main()
|
from sys import stdin, setrecursionlimit
def main():
input = stdin.buffer.readline
n, x, y = map(int, input().split())
ans = [0] * (n - 1)
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
d = min(j - i, abs(i - x) + abs(j - y) + 1, abs(i - y) + abs(j - x) + 1)
ans[d - 1] += 1
print(*ans, sep='\n')
if __name__ == "__main__":
setrecursionlimit(10000)
main()
|
p02726
|
#!/usr/bin/env python3
# coding: utf-8
# import pprint
# import numpy as np
# import code
import functools
def debug(arg):
if __debug__:
pass
else:
import sys
debug = lambda *x: None
print(arg, file=sys.stderr)
n, x, y = (int(x) for x in input().split())
d = dict.fromkeys(range(1, n), 0)
debug(d)
for i in range(1, n):
for j in range(i + 1, n + 1):
debug([i, j, x, y])
dd1=abs(x - i) + 1 + abs(y - j)
dd2= j - i
d[min(dd1, dd2)] += 1
debug(d)
for n in d.values():
print(n)
|
#!/usr/bin/env python3
# coding: utf-8
# import pprint
# import numpy as np
# import code
import functools
if __debug__:
def debug(arg):
pass
else:
import sys
def debug(arg):
debug = lambda *x: None
print(arg, file=sys.stderr)
n, x, y = (int(x) for x in input().split())
d = dict.fromkeys(range(1, n), 0)
debug(d)
for i in range(1, n):
for j in range(i + 1, n + 1):
debug([i, j, x, y])
dd1=abs(x - i) + 1 + abs(y - j)
dd2= j - i
if dd1 < dd2:
d[dd1] += 1
else:
d[dd2] += 1
debug(d)
for n in d.values():
print(n)
|
p02726
|
N, X, Y = map(int, input().split())
def dist(fr, to):
return min(
to - fr,
abs(to - Y) + 1 + abs(fr - X),
abs(fr - Y) + 1 + abs(to - X)
)
cnt = [0] * N
ans = 0
for fr in range(1, N + 1):
for to in range(fr + 1, N + 1):
cnt[dist(fr, to)] += 1
print(*(cnt[1:]), sep='\n')
|
N, X, Y = map(int, input().split())
ans = [0] * N
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
d = min(
j - i,
abs(i - X) + 1 + abs(j - Y),
abs(j - X) + 1 + abs(i - Y)
)
ans[d] += 1
print(*ans[1:], sep='\n')
|
p02726
|
from collections import Counter
import itertools
def warshall_floyd(d):
#d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
n, x, y = list(map(int, input().split()))
d = [[float("inf")]*n for i in range(n)]
for i in range(n-1):
d[i][i+1] = 1
d[i+1][i] = 1
d[x-1][y-1] = 1
d[y-1][x-1] = 1
for i in range(n):
d[i][i] = 0
warshall_floyd(d)
D = Counter(list(itertools.chain.from_iterable(d)))
for i in range(1, n):
print((D[i]//2))
|
from collections import Counter
import itertools
def warshall_floyd(d):
#d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
n, x, y = list(map(int, input().split()))
d = [[n]*n for i in range(n)]
for i in range(n-1):
d[i][i+1] = 1
d[i+1][i] = 1
d[x-1][y-1] = 1
d[y-1][x-1] = 1
for i in range(n):
d[i][i] = 0
warshall_floyd(d)
D = Counter(list(itertools.chain.from_iterable(d)))
for i in range(1, n):
print((D[i]//2))
|
p02726
|
from collections import Counter
import itertools
def warshall_floyd(d):
#d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
n, x, y = list(map(int, input().split()))
d = [[n]*n for i in range(n)]
for i in range(n-1):
d[i][i+1] = 1
d[i+1][i] = 1
d[x-1][y-1] = 1
d[y-1][x-1] = 1
for i in range(n):
d[i][i] = 0
warshall_floyd(d)
D = Counter(list(itertools.chain.from_iterable(d)))
for i in range(1, n):
print((D[i]//2))
|
import collections
n, x, y = list(map(int, input().split()))
d = [[0]*(i+1) for i in range(n)]
x -= 1
y -= 1
for i in range(n):
for j in range(i+1):
d[i][j] = min(i-j, abs(x-j)+abs(y-i)+1)
L = []
for i in range(n):
for dd in d[i]:
L.append(dd)
C = collections.Counter(L)
for i in range(1, n):
print((C[i]))
|
p02726
|
def warshall_floyd(d, n):
for k in range(n):
for i in range(n):
for j in range(n):
if (d[i][k] == 0 or d[k][j] == 0):
continue
if (i == j):
continue
if (d[i][j] == 0):
d[i][j] = d[i][k] + d[k][j]
else:
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
n, x, y = list(map(int, input().split()))
result = [[0] * n for i in range(n)]
for i in range(n):
if (i-1 >= 0):
result[i][i-1] = 1
if (i+1 < n):
result[i][i+1] = 1
result[x-1][y-1] = 1
result[y-1][x-1] = 1
warshall_floyd(result, n)
result_hash = [0] * (n-1)
for i in range(n):
for j in range(n):
if result[i][j] == 0:
continue
result_hash[result[i][j] - 1] += 1
for i in range(n-1):
print((int(result_hash[i] / 2)))
|
n, x, y = list(map(int, input().split()))
result = [0] * n
for i in range(1,n):
for j in range(i+1, n+1):
result[min([(j - i), (abs(i - x) + 1 + abs(j - y))])] += 1
for i in range(1,n):
print((result[i]))
|
p02726
|
N,X,Y =list(map(int,input().split()))
count = [0] * (N-1)
for i in range(1,N):
for j in range(i+1,N+1):
dist = min(j-i, abs(X-i)+1+abs(Y-j))
count[dist-1] +=1
for i in range(N-1):
print((count[i]))
|
N,X,Y =list(map(int,input().split()))
count = [0] * (N-1)
for i in range(1,N):
for j in range(i+1,N+1):
dist = min(j-i, abs(X-i)+1+abs(Y-j))
count[dist-1] +=1
print(("\n".join(map(str,count))))
|
p02726
|
# Using BFS
import queue
from collections import defaultdict
import sys
def input():
return sys.stdin.readline()
def push(v, d, dist, q, INF=1e10):
if dist[v] != INF:
return
dist[v] = d
q.put(v)
def main():
n, x, y = list(map(int, input().split()))
# modify the values of x, y so that they start from zero
x, y = x - 1, y - 1
INF = 1e10
ans = defaultdict(int)
for i in range(n):
# dist[idx]: distance between i and idx.
dist = [INF] * n
q = queue.Queue()
push(i, 0, dist, q)
while not q.empty():
v = q.get()
d = dist[v]
if v - 1 >= 0:
push(v-1, d+1, dist, q)
if v + 1 < n:
push(v+1, d+1, dist, q)
if v == x:
push(y, d+1, dist, q)
if v == y:
push(x, d+1, dist, q)
ans[dist[v]] += 1
for i in range(n):
if i != 0:
print((ans[i] // 2))
if __name__ == "__main__":
main()
|
# Using BFS
from collections import defaultdict, deque
import sys
def input():
return sys.stdin.readline()
def push(v, d, dist, q, INF=1e10):
if dist[v] != INF:
return
dist[v] = d
q.append(v)
def main():
n, x, y = list(map(int, input().split()))
# modify the values of x, y so that they start from zero
x, y = x - 1, y - 1
INF = 1e10
ans = defaultdict(int)
for i in range(n):
# dist[idx]: distance between i and idx.
dist = [INF] * n
q = deque()
push(i, 0, dist, q)
while len(q) != 0:
v = q.popleft()
d = dist[v]
if v - 1 >= 0:
push(v-1, d+1, dist, q)
if v + 1 < n:
push(v+1, d+1, dist, q)
if v == x:
push(y, d+1, dist, q)
if v == y:
push(x, d+1, dist, q)
ans[dist[v]] += 1
for i in range(n):
if i != 0:
print((ans[i] // 2))
if __name__ == "__main__":
main()
|
p02726
|
N, X, Y = list(map(int, input().split()))
dist = [[0 for _ in range(N)] for _ in range(N)]
ans = [0 for _ in range(N)]
for i in range(N):
for j in range(i, N):
tmp1 = abs(i - X + 1) + abs(j - Y + 1) + 1
tmp2 = abs(i - Y + 1) + abs(j - X + 1) + 1
min_dist = min(abs(i - j), tmp1, tmp2)
ans[min_dist - 1] += 1
for i in range(N - 1):
print((ans[i]))
|
N, X, Y = list(map(int, input().split()))
ans = [0 for _ in range(N)]
for i in range(N):
for j in range(i+1, N):
tmp1 = abs(i - X + 1) + abs(j - Y + 1) + 1
tmp2 = abs(i - Y + 1) + abs(j - X + 1) + 1
min_dist = min(abs(i - j), tmp1, tmp2)
ans[min_dist - 1] += 1
for i in range(N - 1):
print((ans[i]))
|
p02726
|
n,x,y=list(map(int,input().split()))
num=[0]*(n-1)
for i in range(n-1):
for j in range(i+1,n):
d=int(min(j-i,abs(x-j-1)+1+abs(y-1-i),abs(y-1-j)+1+abs(x-1-i)))
num[d-1]+=1
for i in range(n-1):
print((num[i]))
|
n,x,y=list(map(int,input().split()))
ans=[0]*n
for i in range(1,n):
for j in range(i+1,n+1):
ans[int(min(j-i,abs(x-i)+abs(y-j)+1))]+=1
for i in range(1,n):
print((ans[i]))
|
p02726
|
# -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N,X,Y = list(map(int, input().split()))
# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|, |Y-i|+1+|j-X|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1,N)]
for i in range(1, N):
for j in range(i+1, N+1):
min_path = min([abs(j-i), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X)])
k_list[min_path-1] += 1
# 結果出力
for k in k_list:
print(k)
|
# -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N,X,Y = list(map(int, input().split()))
# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|, |Y-i|+1+|j-X|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1,N)]
for i in range(1, N):
diff_X_i = abs(X - i)
diff_Y_i = abs(Y - i)
for j in range(i+1, N+1):
diff_j_i = abs(j - i)
diff_j_X = abs(j - X)
diff_j_Y = abs(j - Y)
min_path = min([diff_j_i, diff_X_i+1+diff_j_Y, diff_Y_i+1+diff_j_X])
k_list[min_path-1] += 1
# 結果出力
for k in k_list:
print(k)
|
p02726
|
# -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N,X,Y = list(map(int, input().split()))
# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|, |Y-i|+1+|j-X|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1,N)]
for i in range(1, N):
diff_X_i = abs(X - i)
diff_Y_i = abs(Y - i)
for j in range(i+1, N+1):
diff_j_i = abs(j - i)
diff_j_X = abs(j - X)
diff_j_Y = abs(j - Y)
min_path = min([diff_j_i, diff_X_i+1+diff_j_Y, diff_Y_i+1+diff_j_X])
k_list[min_path-1] += 1
# 結果出力
for k in k_list:
print(k)
|
# -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N,X,Y = list(map(int, input().split()))
# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1,N)]
for i in range(1, N):
for j in range(i+1, N+1):
min_path = min([abs(j-i), abs(X-i)+1+abs(j-Y)])
k_list[min_path-1] += 1
# 結果出力
for k in k_list:
print(k)
|
p02726
|
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False):
inds=sorted(range(len(s)), key=lambda k: s[k])
if return_sorted: return inds, [s[i] for i in inds]
return inds
#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#N = int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
def dk(edge,vis):
q=[[0,vis]]
visited=[False]*N
heapify(q)
while len(q):
e=heappop(q)
if visited[e[1]]:
continue
visited[e[1]]=True
if e[1]>vis:
ans[e[0]]+=1
for ne in edge[e[1]]:
heappush(q,[e[0]+1,ne])
N, X, Y = map(int,input().split()) #n:頂点数 w:辺の数
ans=[0]*(N)
edge = [[] for i in range(N)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(N-1):
x,y=i,i+1
edge[x].append(y)
edge[y].append(x)
edge[X-1].append(Y-1)
edge[Y-1].append(X-1)
for vis in range(N-1):
dk(edge,vis)
#print(ans)
for a in ans[1:]:
print(a)
|
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False):
inds=sorted(range(len(s)), key=lambda k: s[k])
if return_sorted: return inds, [s[i] for i in inds]
return inds
#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#N = int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
mod=10**4
def dk(edge,vis):
q=[vis]
visited=[False]*N
heapify(q)
while len(q):
e=heappop(q)
cd,ce=e//mod, e%mod
if visited[ce]:
continue
#print(cd,ce)
visited[ce]=True
if ce>vis:
ans[cd]+=1
for ne in edge[ce]:
heappush(q,(cd+1)*mod+ne)
N, X, Y = map(int,input().split()) #n:頂点数 w:辺の数
ans=[0]*(N)
edge = [[] for i in range(N)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(N-1):
x,y=i,i+1
edge[x].append(y)
edge[y].append(x)
edge[X-1].append(Y-1)
edge[Y-1].append(X-1)
for vis in range(N-1):
dk(edge,vis)
#print(ans)
for a in ans[1:]:
print(a)
|
p02726
|
# -*- coding: utf-8 -*-
N, X, Y = map(int, input().split())
mid = (X + Y + 1) * 0.5
# GUCHOKU
ans = [0] * N
for i in range(1, N):
for j in range(i, N + 1):
# (i, j)について距離を調べる
# if j >= mid:
# dis = X - i + 1 + abs(j - Y)
# else:
# j - i
dis = min(abs(i - X) + abs(j - Y) + 1, j - i)
ans[dis] += 1
print(*ans[1:], sep='\n')
|
# -*- coding: utf-8 -*-
N, X, Y = map(int, input().split())
mid = (X + Y + 1) * 0.5
# GUCHOKU
ans = [0] * N
for i in range(1, N):
for j in range(i, N + 1):
dis = min(abs(i - X) + abs(j - Y) + 1, j - i)
ans[dis] += 1
print(*ans[1:], sep='\n')
|
p02726
|
import collections
def main():
N,X,Y = list(map(int, input().split()))
# 扱いやすいようにX,Yはインデックス表記にしておく
X -= 1
Y -= 1
# i<jを満たす(i,j)について6通りの場合分けして全最短距離を求められる
shortest = [[-1]*N for _ in range(N)]
for i in range(N):
k1 = abs(X-i)
for j in range(i+1,N):
k2 = abs(j-Y)
shortest[i][j] = min(j-i, k1+1+k2)
coll = [collections.Counter(s) for s in shortest]
for i in range(1,N):
count = 0
for j in range(N):
count += coll[j].get(i,0)
print(count)
main()
|
import collections
def main():
N,X,Y = list(map(int, input().split()))
# 扱いやすいようにX,Yはインデックス表記にしておく
X -= 1
Y -= 1
# i<jを満たす(i,j)について6通りの場合分けして全最短距離を求められる
shortest = [[-1]*N for _ in range(N)]
coll = collections.Counter()
for i in range(N):
k1 = abs(X-i)
for j in range(i+1,N):
k2 = abs(j-Y)
shortest[i][j] = min(j-i, k1+1+k2)
coll += collections.Counter(shortest[i])
for i in range(1,N):
print((coll.get(i,0)))
main()
|
p02726
|
N, X, Y = [int(n) for n in input().split(' ')]
cnt = [0]*N
for i in range(1, N): # 1~N-1
for j in range(i+1, N+1): # 2~N
p = []
p += [j - i]
if i <= X:
if j >= Y:
p += [X-i + j-Y + 1]
else:
p += [X-i + Y-j + 1]
else:
if j >= Y:
p += [i-X + j-Y + 1]
else:
p += [i-X + Y-j + 1]
cnt[min(p)] += 1
for i in range(1, N):
print((cnt[i]))
|
N, X, Y = [int(n) for n in input().split(' ')]
cnt = [0]*N
for i in range(1, N): # 1~N-1
for j in range(i+1, N+1): # 2~N
if i <= X:
if j >= Y:
p = min(X-i + j-Y + 1, j - i)
else:
p = min(X-i + Y-j + 1, j - i)
else:
if j >= Y:
p = min(i-X + j-Y + 1, j - i)
else:
p = min(i-X + Y-j + 1, j - i)
cnt[p] += 1
for i in range(1, N):
print((cnt[i]))
|
p02726
|
from collections import Counter
def min_distance(i,j):
return min(abs(i-j),abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j))
n,x,y=list(map(int,input().split()))
x=x-1
y=y-1
dp=[]
for i in range(n):
for j in range(n):
dp.append(min_distance(i,j))
dic=Counter(dp)
for i in range(1,n):
print((int(dic[i]/2)))
|
from collections import Counter
def min_distance(i,j):
return min(abs(i-j),abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j))
n,x,y=list(map(int,input().split()))
x=x-1
y=y-1
dp=[]
for i in range(n-1):
for j in range(i+1,n):
dp.append(min_distance(i,j))
dic=Counter(dp)
for i in range(1,n):
print((int(dic[i])))
|
p02726
|
from collections import deque
from collections import Counter
def main():
N,X,Y = list(map(int,input().split()))
counter = Counter()
for i in range(1,N+1):
distance = [float("inf")]*(N+1)
q = deque()
q.append(i)
distance[i] = 0
while q:
p = q.popleft()
if p != 1 and p != N:
if distance[p+1] == float("inf"):
if distance[p]+1 < distance[p+1]:
distance[p+1] = distance[p]+1
q.append(p+1)
counter[distance[p]+1] += 1
if distance[p-1] == float("inf"):
if distance[p]+1 < distance[p-1]:
distance[p-1] = distance[p]+1
q.append(p-1)
counter[distance[p]+1] += 1
elif p == 1:
if distance[p+1] == float("inf"):
if distance[p]+1 < distance[p+1]:
distance[p+1] = distance[p]+1
q.append(p+1)
counter[distance[p]+1] += 1
else:
if distance[p-1] == float("inf"):
if distance[p]+1 < distance[p-1]:
distance[p-1] = distance[p]+1
q.append(p-1)
counter[distance[p]+1] += 1
if p == X:
if distance[p]+1 < distance[Y]:
distance[Y] = distance[p]+1
q.append(Y)
counter[distance[p]+1] += 1
if p == Y:
if distance[p]+1 < distance[X]:
distance[X] = distance[p]+1
q.append(X)
counter[distance[p]+1] += 1
for i in range(1,N):
print((counter[i]//2))
if __name__ == "__main__":
main()
|
from collections import Counter
def main():
N,X,Y = list(map(int,input().split()))
counter = Counter()
for i in range(1,N):
for j in range(i+1,N+1):
d = min(j-i,abs(X-i)+abs(Y-j)+1)
counter[d]+=1
for i in range(1,N):
print((counter[i]))
if __name__ == "__main__":
main()
|
p02726
|
N,X,Y = map(int,input().split())
X,Y = X-1,Y-1
from collections import deque
DP = [[-1]*N for _ in range(N)]
ans = [0]*N
for i in range(N):
for j in range(i+1,N):
x = j - (i+1)
y = j
if j <= X or Y <= i:
DP[i][j] = j - i
elif i <= X and Y <= j:
DP[i][j] = X-i + 1 + j-Y
elif i <= X and j <= Y:
DP[i][j] = min(j-i,X-i + 1 + Y-j)
elif X <= i and j <= Y:
DP[i][j] = min(j-i,i-X+1+Y-j)
else:
DP[i][j] = min(j-i,i-X+1+j-Y)
ans[DP[i][j]] += 1
print(*ans[1:],sep='\n')
|
N,X,Y = map(int,input().split())
X,Y = X-1,Y-1
ans = [0]*N
for i in range(N):
for j in range(i+1,N):
if j <= X or Y <= i:
a = j - i
elif i <= X and Y <= j:
a = X-i + 1 + j-Y
elif i <= X and j <= Y:
a = min(j-i,X-i + 1 + Y-j)
elif X <= i and j <= Y:
a = min(j-i,i-X+1+Y-j)
else:
a = min(j-i,i-X+1+j-Y)
ans[a] += 1
print(*ans[1:],sep='\n')
|
p02726
|
n, x, y = list(map(int, input().split()))
ans = [0] * (n-1)
for i in range(n-1):
for j in range(i+1, n):
d = min(j-i, abs(i-x+1)+abs(j-y+1)+1)
ans[d-1] += 1
for a in ans:
print(a)
|
n, x, y = list(map(int, input().split()))
ans = [0] * n
for i in range(n-1):
for j in range(i+1, n):
d = min(j-i, abs(i-x+1)+abs(j-y+1)+1)
ans[d] += 1
ans=ans[1:]
for a in ans:
print(a)
|
p02726
|
N,X,Y=list(map(int,input().split()))
count=[0]*(N-1)
for i in range(1,N+1):
for j in range(i+1,N+1):
d=[]
d.append(abs(j-i))
d.append(abs(X-i)+1+abs(j-Y))
d.append(abs(Y-i)+1+abs(j-X))
count[min(d)-1]+=1
for k in count:
print(k)
|
N,X,Y=list(map(int,input().split()))
count=[0]*(N-1)
for i in range(1,N):
for j in range(i+1,N+1):
num=min(abs(j-i),abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X))
#d=[]
#d.append(abs(j-i))
#d.append(abs(X-i)+1+abs(j-Y))
#d.append(abs(Y-i)+1+abs(j-X))
count[num-1]+=1
for k in count:
print(k)
|
p02726
|
from queue import Queue
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
q = Queue()
ans = [0] * N
def BFS(x, cnt):
if dist[x] != (N + 1):
return
cnt += 1
dist[x] = cnt
if x + 1 < N:
q.put((x + 1, cnt))
if x - 1 >= 0:
q.put((x - 1, cnt))
if x == X:
q.put((Y, cnt))
if x == Y:
q.put((X, cnt))
for x in range(N):
dist = [N + 1] * N
q.put((x, -1))
while not q.empty():
BFS(*q.get())
for i in range(N):
ans[dist[i]] += 1
for x in range(1, N):
print((ans[x] // 2))
|
from collections import deque
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
q = deque()
ans = [0] * N
def BFS(x, cnt):
if dist[x] != (N + 1):
return
cnt += 1
dist[x] = cnt
if x + 1 < N:
q.append((x + 1, cnt))
if x - 1 >= 0:
q.append((x - 1, cnt))
if x == X:
q.append((Y, cnt))
if x == Y:
q.append((X, cnt))
for x in range(N):
dist = [N + 1] * N
q.append((x, -1))
while q:
BFS(*q.popleft())
for i in range(N):
ans[dist[i]] += 1
for x in range(1, N):
print((ans[x] // 2))
|
p02726
|
#!/usr/bin/env python3
N, X, Y = [int(str) for str in input().strip().split()]
INF = 100000
d = [[INF] * N for _ in range(N)]
for i in range(N - 1):
d[i][i + 1] = 1
d[i + 1][i] = 1
d[X - 1][Y - 1] = 1
d[Y - 1][X - 1] = 1
for k in range(N):
for i in range(N):
for j in range(N):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
dists = dict()
for i in range(N):
for j in range(i + 1, N):
k = d[i][j]
dists[k] = dists.get(k, 0) + 1
for k in range(1, N):
print((dists.get(k, 0)))
|
#!/usr/bin/env python3
N, X, Y = [int(str) for str in input().strip().split()]
X -= 1
Y -= 1
dists = [0] * N
for i in range(N - 1):
for j in range(i + 1, N):
d = min(j - i, abs(X - i) + abs(Y - j) + 1)
dists[d] += 1
for k in range(1, N):
print((dists[k]))
|
p02726
|
n, x, y = list(map(int, input().split()))
dis_list = [0] * (n - 1)
for i in range(n - 1):
for j in range(i + 1, n):
dis_list[min(abs(j - i), abs(x - i - 1) + 1 + abs(y - j - 1), abs(y - i - 1) + 1 + abs(x - j - 1)) - 1] += 1
for i in dis_list:
print(i)
|
n, x, y = list(map(int, input().split()))
dis_list = [0] * (n - 1)
for i in range(1, n):
for j in range(i + 1, n + 1):
dis_list[min(abs(j - i), abs(x - i) + 1 + abs(y - j), abs(y - i) + 1 + abs(x - j)) - 1] += 1
for i in dis_list:
print(i)
|
p02726
|
import collections
N,X,Y=list(map(int,input().split()))
if X > Y:
exc=X
X=Y
Y=exc
L=[]
for i in range(N-1):
for j in range(i+1,N):
if i >= Y-1 or j <= X-1:
L.append(j-i)
elif j-i == 1:
L.append(1)
elif i <= X-1 and j >= Y-1:
L.append(1+abs(X-1-i)+abs(Y-1-j))
elif i >= X-1 and i-(X-1) > (Y-1)-i:
L.append(j-i)
else:
L1=j-i
L2=min(j-i,1+abs(X-1-i)+abs(Y-1-j))
L.append(min(L1,L2))
c=collections.Counter(L)
for i in range(1,N):
print((c[i]))
|
N,X,Y=list(map(int,input().split()))
if X > Y:
exc=X
X=Y
Y=exc
L=[0]*N
for i in range(N-1):
for j in range(i+1,N):
if i >= Y-1 or j <= X-1 or j-i ==1:
L[j-i]+=1
elif i <= X-1 and j >= Y-1:
L[1+abs(X-1-i)+abs(Y-1-j)]+=1
elif i >= X-1 and i-(X-1) > (Y-1)-i:
L[j-i]+=1
else:
L1=j-i
L2=min(j-i,1+abs(X-1-i)+abs(Y-1-j))
L[min(L1,L2)]+=1
for i in range(1,N):
print((L[i]))
|
p02726
|
from collections import deque
import collections
n,x,y = list(map(int,input().split()))
connect=[[i-1,i+1] for i in range(1,n-1)]
connect.insert(0,[1])
connect.append([n-2])
connect[x-1].append(y-1)
connect[y-1].append(x-1)
dist_from_i = []
for i in range(0,n):
d=0
dist = [10**6]*n
dq=deque()
dq.append([i,d])
dist[i]=d
while len(dq):
x,d = dq.popleft()
for nextx in connect[x]:
if d<dist[nextx]:
dq.append([nextx,d+1])
dist[nextx] = d+1
dist_from_i.append(dist)
c = collections.Counter(sum(dist_from_i,[]))
for k in range(1,n):
print((c[k]//2))
|
n,x,y = list(map(int,input().split()))
dist = [0]*n
for i in range(0,n-1):
for j in range(i,n):
#xy使わない距離
dist1 = j-i
#xy使う距離
dist2 = abs((x-1) - i) + 1 + abs((y-1) - j)
# print(i,j,dist1,dist2)
#最短距離
dist_min = min(dist1,dist2)
dist[dist_min] += 1
for k in range(1,n):
print((dist[k]))
|
p02726
|
def main():
import collections
n,x,y = list(map(int,input().split(" ")))
dp = [[0]*n for i in range(n)]
for i in range(0,n):
for j in range(i+1,n):
if i < x-1:
if j < x:
dp[i][j] =dp[i][j-1] +1
if j >= x and j < y:
dp[i][j] = dp[i][x-1]+min(j-x+1,y-j)
if j >=y:
dp[i][j] = dp[i][y-1]+j-y+1
if i >= x-1 and i < y-1:
if j < y:
dp[i][j] = dp[i][x-1]+min(j-i,y-x+1-(j-i))
if j >=y:
dp[i][j] = dp[i][y-1]+j-y+1
if i >= y-1:
dp[i][j] = dp[i][j-1] + 1
dp_fl = dp[0]
for i in range(1,n):
dp_fl += dp[i]
cnts = collections.Counter(dp_fl)
for i in range(1,n):
print((cnts.get(i,0)))
main()
|
def main2():
n,x,y = list(map(int,input().split(" ")))
cnts = [0]*n
for i in range(n):
for j in range(i+1,n):
dis = min(j-i,abs(x-1-i)+1+abs(y-1-j))
cnts[dis]+=1
for i in range(1,n):
print((cnts[i]))
main2()
|
p02726
|
N, X, Y = list(map(int, input().split()))
ans = [0]*(N-1)
for i in range(N-1):
for j in range(i+1,N):
dist = min(j-i, min(abs(X-1-i)+1+abs(Y-1-j), abs(Y-1-i)+1+abs(X-1-j)))
ans[dist-1] += 1
for i in range(N-1):
print((ans[i]))
|
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
N, X, Y = list(map(int, input().split()))
ans = [0]*(N-1)
for i in range(N-1):
for j in range(i+1,N):
dist = min(j-i, min(abs(X-1-i)+1+abs(Y-1-j), abs(Y-1-i)+1+abs(X-1-j)))
ans[dist-1] += 1
for i in range(N-1):
print((ans[i]))
|
p02726
|
from collections import deque
N, X, Y = list(map(int, input().split()))
# N = 2000
# X = 100
# Y = 1900
X -= 1
Y -= 1
# @profile
def main(N, X, Y):
ans = [0]*N
for sv in range(N):
# dist[v] = dist from sv to v
dist = [float("inf")]*N
visited = deque()
dist[sv] = 0
visited.appendleft(sv)
while visited:
v = visited.pop()
d = dist[v]
if v+1 < N and dist[v+1] == float("inf"):
dist[v+1] = d+1
visited.appendleft(v+1)
if v-1 >= 0 and dist[v-1] == float("inf"):
dist[v-1] = d+1
visited.appendleft(v-1)
if v == X and dist[Y] == float("inf"):
dist[Y] = d+1
visited.appendleft(Y)
if v == Y and dist[X] == float("inf"):
dist[X] = d+1
visited.appendleft(X)
# print(dist)
for d in dist:
ans[d] += 1
for a in ans[1:]:
print((a//2))
main(N, X, Y)
|
N, X, Y = list(map(int, input().split()))
# N = 2000
# X = 100
# Y = 1900
X -= 1
Y -= 1
# @profile
def main(N, X, Y):
ans = [0]*N
for i in range(N):
for j in range(i+1, N):
d = min(j-i, abs(X-i)+abs(Y-j)+1)
ans[d] += 1
for a in ans[1:]:
print(a)
main(N, X, Y)
|
p02726
|
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
N, X, Y = LI()
X -= 1
Y -= 1
dist = [[N] * N for _ in range(N)]
for i in range(N):
q = deque()
q.append(i)
dist[i][i] = 0
while q:
u = q.popleft()
if u < N - 1:
if dist[i][u + 1] > dist[i][u] + 1:
q.append(u + 1)
dist[i][u + 1] = dist[i][u] + 1
if u >= 1:
if dist[i][u - 1] > dist[i][u] + 1:
q.append(u - 1)
dist[i][u - 1] = dist[i][u] + 1
if u == X:
if dist[i][Y] > dist[i][u] + 1:
q.append(Y)
dist[i][Y] = dist[i][u] + 1
if u == Y:
if dist[i][X] > dist[i][u] + 1:
q.append(X)
dist[i][X] = dist[i][u] + 1
cnt = [0] * N
for i in range(N):
for j in range(i + 1, N):
cnt[dist[i][j]] += 1
for i in cnt[1:]:
print(i)
main()
|
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
N, X, Y = LI()
X -= 1
Y -= 1
dist = [[N] * N for _ in range(N)]
q = deque()
for i in range(N):
q.append(i)
dist[i][i] = 0
while q:
u = q.popleft()
if u < N - 1:
if dist[i][u + 1] > dist[i][u] + 1:
q.append(u + 1)
dist[i][u + 1] = dist[i][u] + 1
if u >= 1:
if dist[i][u - 1] > dist[i][u] + 1:
q.append(u - 1)
dist[i][u - 1] = dist[i][u] + 1
if u == X:
if dist[i][Y] > dist[i][u] + 1:
q.append(Y)
dist[i][Y] = dist[i][u] + 1
if u == Y:
if dist[i][X] > dist[i][u] + 1:
q.append(X)
dist[i][X] = dist[i][u] + 1
cnt = [0] * N
for i in range(N):
for j in range(i + 1, N):
cnt[dist[i][j]] += 1
for i in cnt[1:]:
print(i)
main()
|
p02726
|
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
N, X, Y = LI()
X -= 1
Y -= 1
dist = [[N] * N for _ in range(N)]
q = deque()
for i in range(N):
q.append(i)
dist[i][i] = 0
while q:
u = q.popleft()
t = dist[i][u] + 1
if u < N - 1:
if dist[i][u + 1] > t:
q.append(u + 1)
dist[i][u + 1] = t
if u >= 1:
if dist[i][u - 1] > t:
q.append(u - 1)
dist[i][u - 1] = t
if u == X:
if dist[i][Y] > t:
q.append(Y)
dist[i][Y] = t
if u == Y:
if dist[i][X] > t:
q.append(X)
dist[i][X] = t
cnt = [0] * N
for i in range(N):
for j in range(i + 1, N):
cnt[dist[i][j]] += 1
for i in cnt[1:]:
print(i)
main()
|
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
N, X, Y = LI()
X -= 1
Y -= 1
cnt = [0] * N
for i in range(N):
for j in range(i + 1, N):
dist = min(abs(i - j), abs(X - i) + 1 +
abs(Y - j), abs(Y - i) + 1 + abs(X - j))
cnt[dist] += 1
for i in cnt[1:]:
print(i)
main()
|
p02726
|
N,X,Y=list(map(int,input().split()))
def shortest(x,y,a,b):
ans=min(y-x,abs(y-b)+1+abs(a-x),abs(y-a)+1+abs(b-x))
return ans
distance=[0]*N
for x in range(1,N+1):
for y in range(1,N+1):
if y<=x:
continue
else:
a=shortest(x,y,X,Y)
distance[a-1]+=1
for i in range(N-1):
print((distance[i]))
|
N,X,Y=list(map(int,input().split()))
def shortest(x,y,a,b):
ans=min(y-x,abs(y-b)+1+abs(a-x))
return ans
distance=[0]*(N-1)
for x in range(1,N):
for y in range(2,N+1):
if y<=x:
continue
a=shortest(x,y,X,Y)
distance[a-1]+=1
for i in distance:
print(i)
|
p02726
|
from collections import deque
from itertools import combinations
def main():
n, x, y = [int(e) for e in input().split()]
D = dict()
D[1] = {2}
D[n] = {n - 1}
for i in range(2, n):
D[i] = {i - 1, i + 1}
D[x].add(y)
D[y].add(x)
A = [0]*(n - 1)
for c in combinations(list(range(1, n + 1)), 2):
Q = deque()
Q.extend(D[c[0]])
cnt = 0
end = False
while not end:
cnt += 1
Qex = set()
while len(Q) != 0:
e = Q.popleft()
if e == c[1]:
Q.clear()
end = True
break
Qex |= D[e]
Q.extend(Qex)
A[cnt - 1] += 1
for a in A:
print(a)
if __name__ == "__main__":
main()
|
from itertools import combinations
def main():
n, x, y = [int(e) for e in input().split()]
A = [0]*(n - 1)
for c in combinations(list(range(1, n + 1)), 2):
cnt = min(abs(c[1] - c[0]), abs(c[1] - y) + abs(c[0] - x) + 1, abs(c[1] - x) + abs(c[0] - y) + 1)
A[cnt - 1] += 1
for a in A:
print(a)
if __name__ == "__main__":
main()
|
p02726
|
n,x,y = list(map(int,input().split()))
r = [[] for i in range(n)]
for i in range(n):
if i==0:
r[i].append(i+1)
elif i==n-1:
r[i].append(n-2)
else:
r[i].append(i-1)
r[i].append(i+1)
#x,yの間に道を追加
x,y = x-1,y-1
r[x].append(y)
r[y].append(x)
from collections import deque
q = deque([0])
dist = [-1]*n
dist[0]=0
ans=[]
for p in range(n):
dist = [-1]*n
dist[p]=0
q = deque([p])
while q:
v = q.popleft()
for j in r[v]:
if dist[j]==-1:
dist[j] = dist[v] + 1
q.append(j)
ans.append(dist)
d={}
for k in range(1,n+1):
d[k]=0
for i in range(n):
for j in range(i+1,n):
d[ans[i][j]]+=1
for k in range(n-1):
print((d[k+1]))
|
n,x,y = list(map(int,input().split()))
x,y = x-1,y-1
d={}
for k in range(1,n):
d[k]=0
for i in range(n):
for j in range(i+1,n):
dist=min(abs(i-j) , abs( i - x ) + 1 + abs(y - j) ,abs( i - y ) + 1 + abs(x - j))
d[dist]+=1
for k in range(1,n):
print((d[k]))
|
p02726
|
import sys
from collections import deque
input = sys.stdin.buffer.readline
def bfs(v):
dist = [f_inf for _ in range(n)]
dist[v] = 0
q = deque()
q.append(v)
while q:
u = q.popleft()
for nv in tree[u]:
if dist[nv] == f_inf:
dist[nv] = dist[u] + 1
q.append(nv)
for d in dist:
res[d] += 1
n, x, y = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for i in range(n - 1):
tree[i].append(i + 1)
tree[i + 1].append(i)
tree[x - 1].append(y - 1)
tree[y - 1].append(x - 1)
f_inf = float("inf")
res = [0 for _ in range(n)]
for i in range(n):
bfs(i)
for i in range(1, n):
print((res[i] // 2))
|
def main():
import sys
from collections import deque
input = sys.stdin.buffer.readline
def bfs(v):
dist = [f_inf for _ in range(n)]
dist[v] = 0
q = deque()
q.append(v)
while q:
u = q.popleft()
for nv in tree[u]:
if dist[nv] == f_inf:
dist[nv] = dist[u] + 1
q.append(nv)
for d in dist:
res[d] += 1
n, x, y = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for i in range(n - 1):
tree[i].append(i + 1)
tree[i + 1].append(i)
tree[x - 1].append(y - 1)
tree[y - 1].append(x - 1)
f_inf = float("inf")
res = [0 for _ in range(n)]
for i in range(n):
bfs(i)
for i in range(1, n):
print((res[i] // 2))
if __name__ == '__main__':
main()
|
p02726
|
import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, x, y = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for i in range(1, n):
tree[i - 1].append(i)
tree[i].append(i - 1)
tree[x - 1].append(y - 1)
tree[y - 1].append(x - 1)
def bfs(v):
dist = [f_inf for _ in range(n)]
dist[v] = 0
q = deque()
q.append(v)
while q:
u = q.popleft()
for nv in tree[u]:
if dist[nv] == f_inf:
dist[nv] = dist[u] + 1
q.append(nv)
for d in dist:
res[d] += 1
res = [0 for _ in range(n)]
for i in range(n):
bfs(i)
for j in range(1, n):
print((res[j] // 2))
if __name__ == '__main__':
resolve()
|
import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
def bfs(root):
dist = [f_inf] * n
dist[root] = 0
que = deque()
que.append(root)
while que:
prev = que.popleft()
for next in tree[prev]:
if dist[next] == f_inf:
dist[next] = dist[prev] + 1
que.append(next)
return dist
n, x, y = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for i in range(n - 1):
tree[i].append(i + 1)
tree[i + 1].append(i)
tree[x - 1].append(y - 1)
tree[y - 1].append(x - 1)
cnt = [0] * n
for i in range(n):
dist = bfs(i)
for d in dist:
cnt[d] += 1
for i in range(1, n):
print((cnt[i] // 2))
if __name__ == '__main__':
resolve()
|
p02726
|
n,x,y = list(map(int,input().split()))
ans = [0]*(n-1)
for i in range(n-1):
for j in range(i+1,n):
dis = min(j-i, abs(j-(x-1))+1+abs((y-1)-i), abs(j-(y-1))+1+abs((x-1)-i))
ans[dis-1] += 1
for i in range(n-1):
print((ans[i]))
|
n,x,y = list(map(int,input().split()))
ans = [0]*(n-1)
for i in range(1,n):
for j in range(i+1,n+1):
dis = min(j-i, abs(j-x)+1+abs(y-i), abs(j-y)+1+abs(x-i))
ans[dis-1] += 1
for i in range(n-1):
print((ans[i]))
|
p02726
|
n, x, y = list(map(int, input().split()))
ans = [0] * n
for i in range(1,n):
for j in range(i+1, n+1):
r1 = j-i
r2 = abs(x-i) + 1 + abs(j-y)
r3 = abs(y-i) + 1 + abs(j-x)
ans[min(r1,r2,r3)] += 1
for i in range(1,n):
print((ans[i]))
|
def main():
n, x, y = list(map(int, input().split()))
ans = [0] * n
for i in range(1,n):
for j in range(i+1, n+1):
r1 = j-i
r2 = abs(x-i) + 1 + abs(j-y)
r3 = abs(y-i) + 1 + abs(j-x)
ans[min(r1,r2,r3)] += 1
for i in range(1,n):
print((ans[i]))
if __name__ == "__main__":
main()
|
p02726
|
def main():
n, x, y = list(map(int, input().split()))
ans = [0] * n
for i in range(1,n):
for j in range(i+1, n+1):
r1 = j-i
r2 = abs(x-i) + 1 + abs(j-y)
r3 = abs(y-i) + 1 + abs(j-x)
ans[min(r1,r2,r3)] += 1
for i in range(1,n):
print((ans[i]))
if __name__ == "__main__":
main()
|
n,x,y = list(map(int, input().split()))
ans = [0]*n
for i in range(1,n):
for j in range(i+1,n+1):
v1 = j-i
v2 = abs(x-i) + 1 + abs(y-j)
v3 = abs(y-i) + 1 + abs(x-j)
minv = min(v1,v2,v3)
ans[minv] += 1
for a in ans[1:]:
print(a)
|
p02726
|
import sys
input = sys.stdin.readline
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N,X,Y=MI()
X-=1
Y-=1
##########################################
import heapq
class Dijkstra():
"""
・有向 / 無向は問わない(無向の場合は,逆向きの辺もたす)
・負のコストがない場合のみ
・計算量はO(E log|V|)
・heapを使うことで頂点を走査する必要がなくなる(代わりに,距離更新したものは確定でなくともqueに入れておく)
"""
#最短のpathをたす
class Edge():
#重み付き有向辺
def __init__(self, _to, _cost):
self.to =_to
self.cost = _cost
def __init__(self, V):
#引数Vは頂点数
self.G = [[] for _ in range(V)] #隣接リストG[u][i]が頂点uのi番目の辺
self. _E = 0 #辺の数
self._V = V #頂点数
#proparty - 辺の数
def E(self):
return self._E
#proparty - 頂点数
def V(self):
return self._V
def add(self, _from, _to, _cost):
#2頂点と辺のコストを追加
self.G[_from].append(self.Edge(_to,_cost))
self._E +=1
def add2(self, _from, _to, _cost):
#2頂点と辺のコスト(無向)を追加
self.G[_from].append(self.Edge(_to, _cost))
self.G[_to].append(self.Edge(_from, _cost))
self._E +=1
def shortest_path(self,s):
#始点sから頂点iまでの最短経路長のリストを返す
que = [] #priority queue
d = [float("inf")] * self.V()
prev = [None]*self.V() #prev[j]は,sからjへ最短経路で行くときのjの一つ前の場所
d[s] = 0
heapq.heappush(que,(0,s)) #始点の距離と頂点番号をヒープに追加
while len(que)!=0:
#キューに格納されてある中で一番コストが小さい頂点を取り出す
cost,v = heapq.heappop(que)
#キューに格納された最短経路長候補がdの距離よりも大きい場合に処理をスキップ
if d[v] < cost:
continue
#頂点vに隣接する各頂点iに対して,vを経由した場合の距離を計算して,これがd[i]よりも小さい場合に更新
for i in range(len(self.G[v])):
e = self.G[v][i] #vのi個目の隣接辺
if d[e.to] > d[v] + e.cost:
d[e.to] = d[v] + e.cost #更新
prev[e.to] = v
heapq.heappush(que,(d[e.to],e.to)) #queに新たな最短経路長候補を追加
return d
########################
djk = Dijkstra(N)
for i in range(N-1):
djk.add2(i,i+1,1)
djk.add2(X,Y,1)
ans=[0]*(N+1)
for i in range(N):
d=djk.shortest_path(i)
for j in range(N):
ans[d[j]]+=1
for i in range(N-1):
print((ans[i+1]//2))
main()
|
import sys
input = sys.stdin.readline
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N,X,Y=MI()
X-=1
Y-=1
ans=[0]*N
for i in range(N):
for j in range(i+1,N):
d=min(j-i,abs(X-i)+1+abs(Y-j))
ans[d-1]+=1
for i in range(N-1):
print((ans[i]))
main()
|
p02726
|
N,X,Y = list(map(int, input().split()))
ans = [0]*(N-1)
for i in range(1, N+1):
for j in range(i+1, N+1):
if j <= X:
ans[j-i-1] += 1
elif i <= X:
ans[min(j-i, X-i+1+abs(Y-j))-1] += 1
elif i < Y:
ans[min(j-i, i-X+abs(j-Y)+1)-1] += 1
else:
ans[j-i-1] += 1
for a in ans:
print(a)
|
N,X,Y = list(map(int, input().split()))
ans = [0]*N
for i in range(1, N+1):
for j in range(i+1, N+1):
d = min(j-i, abs(i-X)+1+abs(j-Y))
ans[d] += 1
for i in range(1, N):
print((ans[i]))
|
p02726
|
import sys
import queue
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
IN=lambda : list(map(int, input().split()))
mod=1000000007
#+++++
def main():
n, x, y = IN()
al=[]
for i in range(n):
ll=[-1]*n
ll[i]=0
ol=queue.Queue()
ol.put(i)
while not ol.empty():
pp=ol.get()
if pp+1 < n and ll[pp+1]==-1:
ll[pp+1]=ll[pp]+1
ol.put(pp+1)
if pp -1 >= 0 and ll[pp-1]==-1:
ll[pp-1]=ll[pp]+1
ol.put(pp-1)
if pp == x-1 and ll[y-1]==-1:
ll[y-1] = ll[pp]+1
ol.put(y-1)
if pp == y-1 and ll[x-1]==-1:
ll[x-1] = ll[pp]+1
ol.put(x-1)
al.append(ll)
rr=[0]*n
for i in range(n):
for j in range(i+1,n):
rr[ al[i][j] ]+=1
for v in rr[1:]:
print(v)
def main2():
n, x, y = IN()
al=[[-1]*n for _ in range(n)]
ol=queue.Queue()
for i in range(n):
al[i][i]=0
for i in range(n-1):
al[i][i+1]=1
ol.put((i,i+1))
al[i+1][i]=1
al[x-1][y-1]=1
ol.put((x-1, y-1))
al[y-1][x-1]=1
while not ol.empty():
#print(ol.qsize())
fp, tp = ol.get()
for i, dist in enumerate(al[tp]):
nd = al[fp][tp] + dist
if dist > 0 and (al[fp][i] == -1 or al[fp][i] > nd) and fp < i:
al[fp][i]=nd
al[i][fp]=nd
ol.put((fp,i))
fp,tp=tp,fp
for i, dist in enumerate(al[tp]):
nd = al[fp][tp] + dist
if dist > 0 and (al[fp][i] == -1 or al[fp][i] > nd) and fp < i:
al[fp][i]=nd
al[i][fp]=nd
ol.put((fp,i))
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
import sys
from collections import deque
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
IN=lambda : list(map(int, input().split()))
mod=1000000007
#+++++
def main():
n, x, y = IN()
al=[]
for i in range(n):
ll=[0]*n
for j in range(n-i):
ll[i+j]=j
for j in range(i+1):
ll[i-j]=j
df = x-1
dt = y-1
if ll[y-1] < ll[x-1]:
df, dt = dt, df
if ll[dt] < ll[df]+1:
al.append(ll)
continue
ll[dt] = ll[df]+1
for i in range(dt+1,n):
if ll[i] < ll[i-1]+1:
break
ll[i]=ll[i-1]+1
for i in range(dt-1,0,-1):
if ll[i] < ll[i+1]+1:
break
ll[i]=ll[i+1]+1
al.append(ll)
#for l in al:
# print(l)
rr=[0]*n
for i in range(n):
for j in range(i+1,n):
rr[ al[i][j] ]+=1
for v in rr[1:]:
print(v)
def main2():
n, x, y = IN()
al=[[-1]*n for _ in range(n)]
ol=queue.Queue()
for i in range(n):
al[i][i]=0
for i in range(n-1):
al[i][i+1]=1
ol.put((i,i+1))
al[i+1][i]=1
al[x-1][y-1]=1
ol.put((x-1, y-1))
al[y-1][x-1]=1
while not ol.empty():
#print(ol.qsize())
fp, tp = ol.get()
for i, dist in enumerate(al[tp]):
nd = al[fp][tp] + dist
if dist > 0 and (al[fp][i] == -1 or al[fp][i] > nd) and fp < i:
al[fp][i]=nd
al[i][fp]=nd
ol.put((fp,i))
fp,tp=tp,fp
for i, dist in enumerate(al[tp]):
nd = al[fp][tp] + dist
if dist > 0 and (al[fp][i] == -1 or al[fp][i] > nd) and fp < i:
al[fp][i]=nd
al[i][fp]=nd
ol.put((fp,i))
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
p02726
|
n,x,y=list(map(int,input().split()))
x-=1
y-=1
cnt=[0]*n
for i in range(n):
for j in range(i+1,n):
dist=min(j-i,abs(j-x)+1+abs(i-y),abs(j-y)+1+abs(i-x))
cnt[dist]+=1
for i in range(1,n):
print((cnt[i]))
|
N,X,Y=list(map(int,input().split()))
X-=1#0-indexへ
Y-=1
dist=[0]*(N+1)
for i in range(N):
for j in range(i+1,N):
d=min(j-i,abs(j-X)+1+abs(i-Y),abs(j-Y)+1+abs(i-X))
#通常ルートとバイパスを通った時を比べて小さい方を取る
dist[d]+=1#該当の距離に相応するパスの個数を1個追加する
for i in range(1,N):#距離が1以上のパスの個数を順番に出力
print((dist[i]))
|
p02726
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.