input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
#Fukushimaken:
from heapq import heappop, heappush
OUT, IN = 0, 1
def P(i):
return 31 if i % 5 == 1 else 3
def M(i):
return 17 * (i % 2) + 3 * (i % 3) + 19
def check(c, n):
for i in range(16):
if (c >> i) & n == 0:
return i
return None
ans = [-1] * 100 + [0]
eq = [(i * 5, i, IN, None, P(i)) for i in range(100)]
c = 1 << 17
while len(eq) != 0:
m, n, et, i, p = heappop(eq)
if et == IN:
i = check(c, p)
if ans[n-1] != -1 and i is not None:
c = c | (p << i)
ans[n] = m - n * 5
heappush(eq, (m + M(n), n, OUT, i, p))
else:
heappush(eq, (m + 1, n, IN, None, p)) #
else:
c = c ^ (p << i)
while True:
try:
n = eval(input())
print(ans[n])
except:
break
|
#Fukushimaken:
from heapq import heappop, heappush
def P(i):
return 31 if i % 5 == 1 else 3
def M(i):
return 17 * (i % 2) + 3 * (i % 3) + 19
def check(c, n):
for i in range(16):
if (c >> i) & n == 0:
return i
return None
ans = [-1] * 100 + [0]
eq = [(i * 5, i, None, P(i)) for i in range(100)]
c = 1 << 17
while len(eq) != 0:
m, n, i, p = heappop(eq)
if i is None:
i = check(c, p)
if ans[n-1] != -1 and i is not None:
c = c | (p << i)
ans[n] = m - n * 5
heappush(eq, (m + M(n), n, i, p))
else:
heappush(eq, (m + 1, n, None, p)) #
else:
c = c ^ (p << i)
while True:
try:
print(ans[eval(input())])
except:
break
|
p00147
|
n,x,y=list(map(int,input().split()))
x-=1
y-=1
a=[]
for i in range(n):
a.append(0)
for i in range(n):
for j in range(n):
if i<j:
p=min(abs(j-i),abs(x-i)+abs(y-j)+1,abs(y-i)+abs(x-j)+1)
a[p]+=1
for i in range(n-1):
print((str(a[i+1])))
|
n,x,y=list(map(int,input().split()))
x-=1
y-=1
a=[]
for i in range(n):
a.append(0)
for i in range(n-1):
for j in range(n-i):
j=n-1-j
p=min(abs(j-i),abs(x-i)+abs(y-j)+1,abs(y-i)+abs(x-j)+1)
a[p]+=1
for i in range(n-1):
print((str(a[i+1])))
|
p02726
|
N, X, Y = map(int, input().split())
X = X-1
Y = Y-1
cnt = [0]*N
for i in range(N):
for j in range(N):
if j >= i:
continue
dist = min(abs(i-j),
abs(X-i) + abs(Y-j) + 1,
abs(X-j) + abs(Y-i) + 1)
cnt[dist] += 1
print(*cnt[1:], sep='\n')
|
N, X, Y = map(int, input().split())
X = X-1
Y = 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) + abs(Y-j) + 1,
abs(X-j) + abs(Y-i) + 1)
cnt[dist] += 1
print(*cnt[1:], sep='\n')
|
p02726
|
import sys
input = sys.stdin.readline
import collections
N, X, Y = list(map(int, input().split()))
def bfs(i, j):
dist = [-1]*N
dist[i] = 0
que = collections.deque([])
que.append(i)
while len(que) != 0:
v = que.popleft()
for nv in graph[v]:
if dist[nv] != -1:continue
dist[nv] = dist[v]+1
if nv == j:break
que.append(nv)
return dist[j]
graph = {}
for i in range(N):
graph[i] = set()
for i in range(N-1):
graph[i].add(i+1)
graph[i+1].add(i)
graph[X-1].add(Y-1)
graph[Y-1].add(X-1)
ans = [0]*N
for i in range(N):
for j in range(i+1,N):
d = bfs(i,j)
ans[d] += 1
for i in range(N):
if i == 0:continue
print((ans[i]))
|
import sys
input = sys.stdin.readline
import collections
N, X, Y = list(map(int, input().split()))
def bfs(i):
dist = [-1]*N
dist[i] = 0
que = collections.deque([])
que.append(i)
while len(que) != 0:
v = que.popleft()
for nv in graph[v]:
if dist[nv] != -1:continue
dist[nv] = dist[v]+1
que.append(nv)
return dist[i+1:]
graph = {}
for i in range(N):
graph[i] = set()
for i in range(N-1):
graph[i].add(i+1)
graph[i+1].add(i)
graph[X-1].add(Y-1)
graph[Y-1].add(X-1)
d = collections.Counter([])
for i in range(N):
d += collections.Counter(bfs(i))
for i in range(1,N):
if i == N-1:
print((0))
else:
print((d[i]))
|
p02726
|
import sys
input = sys.stdin.readline
import collections
N, X, Y = list(map(int, input().split()))
def bfs(i):
dist = [-1]*N
dist[i] = 0
que = collections.deque([])
que.append(i)
while len(que) != 0:
v = que.popleft()
for nv in graph[v]:
if dist[nv] != -1:continue
dist[nv] = dist[v]+1
que.append(nv)
return dist[i+1:]
graph = {}
for i in range(N):
graph[i] = set()
for i in range(N-1):
graph[i].add(i+1)
graph[i+1].add(i)
graph[X-1].add(Y-1)
graph[Y-1].add(X-1)
d = collections.Counter([])
for i in range(N):
d += collections.Counter(bfs(i))
for i in range(1,N):
if i == N-1:
print((0))
else:
print((d[i]))
|
import sys
input = sys.stdin.readline
from collections import deque
from collections import Counter
def main():
N, X, Y = list(map(int, input().split()))
graph = {}
for i in range(N):
graph[i] = set()
for i in range(N-1):
graph[i].add(i+1)
graph[i+1].add(i)
graph[X-1].add(Y-1)
graph[Y-1].add(X-1)
ans = []
for i in range(N):
dist = [-1] * N
dist[i] = 0
que = deque([])
que.append(i)
while len(que) != 0:
v = que.popleft()
for nv in graph[v]:
if dist[nv] != -1:continue
dist[nv] = dist[v] + 1
que.append(nv)
ans += dist
ans = Counter(ans)
for i in range(1, N):
print((ans[i]//2))
if __name__ == "__main__":
main()
|
p02726
|
def main():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
print(N)
for k in range(2, N):
ans = 0
for i in range(N):
ans += sum(1 for j in range(i + 1, N)
if min(j - i, abs(i - X) + abs(j - Y) + 1) == k)
print(ans)
main()
|
def main():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
print(N)
dist = [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)
dist[d] += 1
for k in range(2, N):
print((dist[k]))
main()
|
p02726
|
from itertools import combinations
from collections import defaultdict
inf=10**7
n,x,y=list(map(int,input().split()))
x-=1
y-=1
dis={}
cnt=defaultdict(int)
for i,j in combinations(list(range(n)),2):
dis[(i,j)]=min(abs(j-i),abs(j-y)+1+abs(i-x),abs(j-x)+1+abs(i-y))
for i,j in combinations(list(range(n)),2):
cnt[dis[(i,j)]]+=1
for k in range(1,n):
print((cnt[k]))
|
from itertools import combinations
from collections import defaultdict
n,x,y=list(map(int,input().split()))
x-=1
y-=1
cnt=defaultdict(int)
for i,j in combinations(list(range(n)),2):
cnt[min(abs(j-i),abs(j-y)+1+abs(i-x),abs(j-x)+1+abs(i-y))]+=1
for k in range(1,n):
print((cnt[k]))
|
p02726
|
def main():
N,X,Y = list(map(int,input().split()))
d = [[float('inf') for _ in range(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 i in range(N):
d[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
d[i][j] = min(d[i][k]+d[k][j],d[i][j])
#print(d)
ans = [0 for _ in range(N-1)]
for i in range(N-1):
for j in range(i,N):
if 0 < d[i][j] < N:
ans[d[i][j]-1] += 1
for i in range(N-1):
print((ans[i]))
main()
|
def main():
N,X,Y = list(map(int,input().split()))
V = [[] for _ in range(N)]
for i in range(N-1):
V[i].append(i+1)
V[i+1].append(i)
X -= 1
Y -= 1
V[X].append(Y)
V[Y].append(X)
#print(V)
ans = [0 for _ in range(N)]
INF = float('INF')
for s in range(N):
D = [INF for _ in range(N)]
q = [s]
d = 0
while(q):
q2 = []
for v in q:
D[v] = min(D[v],d)
for u in V[v]:
if D[u] == INF:
q2.append(u)
q = q2[:]
d += 1
#print(q,d,D)
for i in range(N):
ans[D[i]] += 1
for i in range(1,N):
print((ans[i]//2))
main()
|
p02726
|
n,x,y=list(map(int,input().split()))
ans=[0 for _ in range(n+1)]
d=[]
for i in range(n+1):
d.append([abs(i-j) for j in range(n+1)])
# print(d[i])
d[x][y]=1
d[y][x]=1
for i in range(1,n+1):
for j in range(i+1,n+1):
d[i][j]=min(d[i][j],d[i][x]+d[x][y]+d[y][j],d[i][y]+d[y][x]+d[x][j])
ans[d[i][j]]+=1
for i in range(1,n):
print((ans[i]))
|
n,x,y=list(map(int,input().split()))
ans=[0 for _ in range(n+1)]
for i in range(1,n+1):
for j in range(i+1,n+1):
ans[min(abs(j-i),abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(j-x))]+=1
for i in range(1,n):
print((ans[i]))
|
p02726
|
n,x,y=list(map(int,input().split()))
dist=[[0 for i in range(n)] for j in range(n)]
m=n
connection=[[] for i in range(n)]
for i in range(n-1):
connection[i].append(i+1)
for i in range(1,n):
connection[i].append(i-1)
connection[x-1].append(y-1)
connection[y-1].append(x-1)
def bfs(v):
distance=[-1]*n
distance[v]=0
next=connection[v]
next2=set()
visited=[-1]*n
visited[v]=1
visitct=1
ct=0
while len(next)!=0 and visitct!=n:
ct+=1
for i in range(len(next)):
if visited[next[i]]==-1:
distance[next[i]]=ct
visited[next[i]]=1
visitct+=1
for j in range(len(connection[next[i]])):
if visited[connection[next[i]][j]]==-1:
next2.add(connection[next[i]][j])
next=list(next2)
next2=set()
return distance
ct=[0 for i in range(n)]
for i in range(n):
b=bfs(i)
for j in range(n):
ct[b[j]]+=1
for i in range(1,n):
print((ct[i]//2))
|
n,x,y=list(map(int,input().split()))
ct=[0 for i in range(n)]
for i in range(n):
for j in range(i+1,n):
ct[min(j-i,abs(j-y+1)+abs(i-x+1)+1)]+=1
for i in range(1,n):
print((ct[i]))
|
p02726
|
from collections import defaultdict
N, X, Y = list(map(int, input().split()))
dists = defaultdict(lambda: N)
for k in range(1, N):
for i in range(1 + k, N + 1):
dists[(i - k, i)] = min(dists[(i - k, i)], k)
for i in range(k):
for a, b in (
(X - i, Y + k - 1 - i),
(X - i, Y - (k - 1 - i)),
(X + i, Y + k - 1 - i),
(X + i, Y - (k - 1 - i)),
):
if 1 <= a <= N and 1 <= b <= N and a < b:
dists[(a, b)] = min(dists[(a, b)], k)
d = defaultdict(int)
for v in list(dists.values()):
d[v] += 1
for k in range(1, N):
print((d.get(k, 0)))
|
N, X, Y = list(map(int, input().split()))
dists = [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)
dists[d] += 1
for k in range(1, N):
print((dists[k]))
|
p02726
|
from collections import *
nxy=input().rstrip().split(" ")
n=int(nxy[0])
x=int(nxy[1])
y=int(nxy[2])
dis=[]
for i in range(1,n):
#print(i)
j=i+1
while j>i and j<=n:
l1=abs(x-i)+1+abs(y-j)
l2=j-i
if l1>=l2:
L=l2
else:
L=l1
#print(L)
dis.append(L)
j=j+1
#print(dis)
for k in range(1,n):
print((dis.count(k)))
|
import collections
nxy=input().rstrip().split(" ")
n=int(nxy[0])
x=int(nxy[1])
y=int(nxy[2])
dis=[]
for i in range(1,n):
#print(i)
j=i+1
while j>i and j<=n:
l1=abs(x-i)+1+abs(y-j)
l2=j-i
if l1>=l2:
L=l2
else:
L=l1
#print(L)
dis.append(L)
j=j+1
#print(dis)
c=collections.Counter(dis)
#print(c)
for k in range(1,n):
print((c[k]))
|
p02726
|
import queue
n,x,y = list(map(int,input().split()))
l = [0] * n
for z in range(n):
q = queue.Queue()
q.put(z)
d = [-1] * n
d[z] = 0
while(not q.empty()):
i = q.get()
if(d[i] > 0 and i > z):l[d[i]] += 1
j = i + 1
if(j < n):
if(d[j] == -1):
d[j] = d[i] + 1
q.put(j)
j = i - 1
if(j >= 0):
if(d[j] == -1):
d[j] = d[i] + 1
q.put(j)
if(i == x - 1):
j = y - 1
if(d[j] == -1):
d[j] = d[i] + 1
q.put(j)
for i in range(1,n):print((l[i]))
|
import queue
n,x,y = list(map(int,input().split()))
x -= 1
y -= 1
l = [0] * n
for i in range(n):
for j in range(i+1,n):
d = min([abs(j-i),abs(x-i)+1+abs(j-y),abs(y-i)+1+(j-x)])
l[d] += 1
for i in range(1,n):print((l[i]))
|
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):
ans[min(abs(j-i), abs(X-i-1) + 1 + abs(j+1-Y ), abs(Y-i-1) + 1 + abs(j+1-X))-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):
ans[min(abs(j-i), abs(X-i) + 1 + abs(j-Y ), abs(Y-i) + 1 + abs(j-X))-1]+=1
for i in range(N-1):
print((ans[i]))
|
p02726
|
from collections import deque
Q = deque()
N, X, Y = list(map(int, input().split()))
K = [0 for i in range(N)]
edge = [[]for i in range(N+1)]
for i in range(1, N):
edge[i].append(i + 1)
edge[i+1].append(i)
edge[X].append(Y)
edge[Y].append(X)
for i in range(1, N):
Done = [-1 for j in range(N+1)]
Q.append(i)
Done[0] = 0
Done[i] = 0
while len(Q) > 0:
x = Q.popleft()
for y in edge[x]:
if Done[y] >= 0:
continue
else:
Done[y] = Done[x] + 1
Q.append(y)
if y > i:
K[Done[y]] += 1
for z in K[1:]:
print(z)
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
K = [0 for i in range(N)]
for i in range(N-1):
for j in range(i+1, N):
a = abs(j - i)
b = abs(X - i) + 1 + abs(j - Y)
c = abs(Y - i) + 1 + abs(j - X)
K[min(a, b, c)] += 1
for i in range(1, N):
print((K[i]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
K = [0 for i in range(N)]
for i in range(N-1):
for j in range(i+1, N):
a = abs(j - i)
b = abs(X - i) + 1 + abs(j - Y)
c = abs(Y - i) + 1 + abs(j - X)
K[min(a, b, c)] += 1
for i in range(1, N):
print((K[i]))
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
K = [0] * N
for i in range(N-1):
for j in range(i+1, N):
a = abs(j - i)
b = abs(X - i) + 1 + abs(j - Y)
c = abs(Y - i) + 1 + abs(j - X)
K[min(a, b, c)] += 1
for i in range(1, N):
print((K[i]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
g = [[] for i in range(N)]
for i in range(N):
u = i
v = i + 1
if v < N:
g[u].append(v)
g[v].append(u)
g[X - 1].append(Y - 1)
g[Y - 1].append(X - 1)
from collections import deque
dis = [[float('Inf')] * N for _ in range(N)]
count = [0] * (N - 1)
def bfs(i):
d = [False] * N
que = deque()
#for j in g[i]:
que.append(i)
d[i] = True
dis[i][i] = 0
pre = i
while que:
p = que.popleft()
for k in g[p]:
if d[k]:
continue
else:
d[k] = True
que.append(k)
dis[i][k] = dis[i][p] + 1
dis[k][i] = dis[i][p] + 1
count[dis[i][k] - 1] += 1
#count[dis[k][i] - 1] += 1
pre = p
for i in range(N):
bfs(i)
for i in range(N - 1):
print((count[i] // 2))
|
N, X, Y = list(map(int, input().split()))
g = [[] for _ in range(N)]
for i in range(N - 1):
u = i
v = i + 1
g[u].append(v)
g[v].append(u)
g[X - 1].append(Y - 1)
g[Y - 1].append(X - 1)
from collections import deque
dis = [[0] * N for _ in range(N)]
def bfs(i):
visited = [False] * N
que = deque([i])
dis[i][i] = 0
visited[i] = True
while que:
p = que.popleft()
for new in g[p]:
if visited[new]:
continue
else:
visited[new] = True
que.append(new)
dis[i][new] = dis[i][p] + 1
count[dis[i][new] - 1] += 1
count = [0] * (N - 1)
for i in range(N):
bfs(i)
for i in range(N - 1):
print((count[i] // 2))
|
p02726
|
N, X, Y = list(map(int, input().split()))
g = [[] for i in range(N)]
for i in range(N):
u = i
v = i + 1
if v < N:
g[u].append(v)
g[v].append(u)
g[X - 1].append(Y - 1)
g[Y - 1].append(X - 1)
from collections import deque
dis = [[float('Inf')] * N for _ in range(N)]
count = [0] * (N - 1)
def bfs(i):
d = [False] * N
que = deque()
#for j in g[i]:
que.append(i)
d[i] = True
dis[i][i] = 0
pre = i
while que:
p = que.popleft()
for k in g[p]:
if d[k]:
continue
else:
d[k] = True
que.append(k)
dis[i][k] = dis[i][p] + 1
dis[k][i] = dis[i][p] + 1
count[dis[i][k] - 1] += 1
#count[dis[k][i] - 1] += 1
pre = p
for i in range(N):
bfs(i)
for i in range(N - 1):
print((count[i] // 2))
|
N, X, Y = list(map(int, input().split()))
g = [[] for i in range(N)]
for i in range(N):
u = i
v = i + 1
if v < N:
g[u].append(v)
g[v].append(u)
g[X - 1].append(Y - 1)
g[Y - 1].append(X - 1)
from collections import deque
dis = [[float('Inf')] * N for _ in range(N)]
count = [0] * (N - 1)
def bfs(i):
d = [False] * N
que = deque()
#for j in g[i]:
que.append(i)
d[i] = True
dis[i][i] = 0
#pre = i
while que:
p = que.popleft()
for k in g[p]:
if d[k]:
continue
else:
d[k] = True
que.append(k)
dis[i][k] = dis[i][p] + 1
#dis[k][i] = dis[i][p] + 1
count[dis[i][k] - 1] += 1
#count[dis[k][i] - 1] += 1
#pre = p
for i in range(N):
bfs(i)
for i in range(N - 1):
print((count[i] // 2))
|
p02726
|
# -*- coding: utf-8 -*-
if True:
n,x,y = list(map(int, input().split()))
else:
# n=5
# x=2
# y=4
# n=3
# x=1
# y=3
n=7
x=3
y=7
# print(n)
# print(x)
# print(y)
#
ret = [0] * (n-1)
for i in range(1, n):
for j in range(i+1, n+1):
# print(str(i) + "," + str(j))
p =[]
p.append(j - i)
p.append(abs(i - x) + 1 + abs(j - y))
p.append(abs(i - y) + 1 + abs(j - x))
# print(p)
# print(min(p))
ret[min(p)-1] += 1
# print(ret)
# print("=======")
for data in ret:
print(data)
|
n,x,y = list(map(int, input().split()))
ret = [0] * (n-1)
for i in range(1, n):
for j in range(i+1, n+1):
p1 = j-i
p2 = abs(i - x) + 1 + abs(j - y)
p3 = abs(i - y) + 1 + abs(j - x)
if p1 > p2:
p1 = p2
if p1 > p3:
p1 = p3
ret[p1-1] += 1
for data in ret:
print(data)
|
p02726
|
n, x, y = list(map(int, input().split()))
king_li = []
for i in range(1, n+1):
for j in range(i+1,n+1):
li = []
li.append(abs(y-j)+abs(x-i)+1)
li.append(j-i)
king_li.append(min(li))
for z in range(1,n):
print((king_li.count(z)))
|
n, x, y = list(map(int, input().split()))
dic={}
for i in range(1, n+1):
for j in range(i+1,n+1):
m = min(abs(y-j)+abs(x-i)+1,j-i)
if m in list(dic.keys()):
dic[m] += 1
else:
dic[m] =1
for z in range(1,n):
if z in list(dic.keys()):
print((dic[z]))
else:
print((0))
|
p02726
|
N, X, Y = list(map(int, input().split()))
minus = []
plus = []
for A in range(1,N):
for B in range(A+1,N+1):
if B - A > abs(X -A) + abs(Y - B) + 1:
minus.append(B-A)
plus.append(abs(X -A) + abs(Y - B) + 1)
for k in range(1,N):
print((N - k - minus.count(k) + plus.count(k)))
|
N, X, Y = list(map(int, input().split()))
ks = [0]*(N-1)
for A in range(1,N):
for B in range(A+1,N+1):
if B - A > abs(X -A) + abs(Y - B) + 1:
ks[B-A-1] -= 1
ks[abs(X -A) + abs(Y - B)] += 1
for k in range(1,N):
print((N - k + ks[k-1]))
|
p02726
|
def solve(string):
n, x, y = list(map(int, string.split()))
ans = [0] * (n - 1)
for s in range(1, n + 1):
d = [abs(i - s) for i in range(1, n + 1)]
if d[x - 1] < d[y - 1]:
p = y - 1
d[p] = min(d[p], d[x - 1] + 1)
else:
p = x - 1
d[p] = min(d[p], d[y - 1] + 1)
for i in range(p + 1, n):
d[i] = min(d[i], d[i - 1] + 1)
for i in range(p - 1, -1, -1):
d[i] = min(d[i], d[i + 1] + 1)
for _d in d[s:]:
ans[_d - 1] += 1
return "\n".join(map(str, ans))
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
|
def solve(string):
n, x, y = list(map(int, string.split()))
ans = [0] * n
for i in range(1, n):
for j in range(i + 1, n + 1):
ans[min(j - i, abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x))] += 1
return "\n".join(map(str, ans[1:]))
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
|
p02726
|
if __name__ == '__main__':
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):
l1 = abs(j-i)
l2 = abs(X-i) + 1 + abs(j-Y)
l3 = abs(Y-i) + 1 + abs(j-X)
lm = min(l1,l2,l3)
ans[lm - 1] += 1
for k in range(N-1):
print((ans[k]))
|
if __name__ == '__main__':
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):
l1 = abs(j-i)
l2 = abs(X-i) + 1 + abs(j-Y)
lm = min(l1,l2)
ans[lm - 1] += 1
for k in range(N-1):
print((ans[k]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for i in range(1, N):
graph[i-1].append(i)
graph[i].append(i-1)
graph[X-1].append(Y-1)
graph[Y-1].append(X-1)
from collections import deque, defaultdict
dic = defaultdict(int)
def bfs(s):
checked = [0]*N
queue = deque([(s, 0)])
while queue:
v, c = queue.pop()
if checked[v]:
continue
checked[v] = 1
dic[c] += 1
for i in graph[v]:
if not checked[i]:
queue.appendleft((i, c+1))
for i in range(N):
bfs(i)
for i in range(1, N):
print((dic[i]//2))
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
N, X, Y = mapint()
X, Y = X-1, Y-1
dist = [0]*(N-1)
for i in range(N-1):
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)
dist[d-1] += 1
for k in range(N-1):
print((dist[k]))
|
p02726
|
# ANSHUL GAUTAM
# IIIT-D
from math import *
from copy import *
from string import * # alpha = ascii_lowercase
from random import * # l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import * # bisect_left(arr,x,start,end) => start and end parameters are temporary
from sys import stdin # bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import * # d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter # d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)
'''
5 2 4
'''
def solve(n,x,y):
adj = [[] for i in range(n+1)]
adj[x].append(y)
adj[y].append(x)
for i in range(1,n):
adj[i].append(i+1)
adj[i+1].append(i)
# print(adj)
ans = []
d = {}
for i in range(1,n):
d[i] = 0
for k in range(1,n+1):
q = [k]
dis = [maxsize]*(n+1)
dis[k] = 0
while(q):
src = q.pop()
for nn in adj[src]:
if(dis[nn] > dis[src]+1):
dis[nn] = dis[src] + 1
q.append(nn)
curr = 0
# print('k:',k,dis)
for ii in range(k+1,n+1):
d[dis[ii]] += 1
return d
N,X,Y = list(map(int, stdin.readline().rstrip().split()))
ans = solve(N,X,Y)
for i in range(1,N):
print((ans[i]))
|
# ANSHUL GAUTAM
# IIIT-D
from math import *
from copy import *
from string import * # alpha = ascii_lowercase
from random import * # l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import * # bisect_left(arr,x,start,end) => start and end parameters are temporary
from sys import stdin # bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import * # d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter # d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)
'''
5 2 4
'''
def solve(n,x,y):
adj = [[] for i in range(n+1)]
adj[x].append(y)
adj[y].append(x)
for i in range(1,n):
adj[i].append(i+1)
adj[i+1].append(i)
# print(adj)
ans = []
d = {}
for i in range(1,n):
d[i] = 0
for k in range(1,n+1):
q = [k]
dis = [maxsize]*(n+1)
dis[k] = 0
while(q):
src = q.pop()
for nn in adj[src]:
# if(nn > k or nn == X or nn == Y):
if(dis[nn] > dis[src]+1):
# if(src == 4):
# print('src:',src,'nn:',nn)
dis[nn] = dis[src] + 1
q.append(nn)
# else:
# dis[nn] =
# if(k == 3):
# print('src:',src)
# print('dis:',dis)
curr = 0
# if(k == 3):
# print('k:',k,dis)
for ii in range(k+1,n+1):
d[dis[ii]] += 1
return d
N,X,Y = list(map(int, stdin.readline().rstrip().split()))
ans = solve(N,X,Y)
for i in range(1,N):
print((ans[i]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
from collections import defaultdict
ans = defaultdict(int)
for i in range(N):
for j in range(i + 1, N):
idx = min(j - i, abs(j + 1 - Y) + 1 + abs(X - i - 1))
ans[idx] += 1
for i in range(1, N):
print((ans[i]))
|
from collections import defaultdict
N, X, Y = list(map(int, input().split()))
ctr = defaultdict(int)
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))
ctr[d] += 1
for i in range(1, N):
print((ctr[i]))
|
p02726
|
from collections import defaultdict
N, X, Y = list(map(int, input().split()))
ctr = defaultdict(int)
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))
ctr[d] += 1
for i in range(1, N):
print((ctr[i]))
|
from collections import defaultdict
N, X, Y = list(map(int, input().split()))
ctr = defaultdict(int)
for u in range(1, N):
for v in range(u + 1, N + 1):
d = min(v - u, abs(u - X) + 1 + abs(Y - v))
ctr[d] += 1
for n in range(1, N):
print((ctr[n]))
|
p02726
|
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):
temp = min(abs(x-i) + 1 + abs(j-y), abs(y-i) + 1 + abs(j-x))
cnt[min(abs(j-i), temp)] += 1
for i in range(1, N):
print((cnt[i]))
|
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):
temp = min(abs(j-i), abs(x-i) + 1 + abs(j-y), abs(y-i) + 1 + abs(j-x))
cnt[temp] += 1
for i in range(1, N):
print((cnt[i]))
|
p02726
|
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N, X, Y = LI()
X -= 1
Y -= 1
path = [[mod for i in range(N)] for i in range(N)]
for i in range(N):
for j in range(i, N):
path[i][j] = j - i
path[j][i] = j- i
path[X][Y] = 1
path[Y][X] = 1
for i in range(N):
for j in range(i + 1, N):
path[i][j] = min(path[i][j], path[i][X] + path[X][Y]+ path[Y][j])
anss = [0 for i in range(N)]
# for p in path:
# print(p)
for i in range(N):
for j in range(i + 1, N):
anss[path[i][j]] += 1
for i in range(1, N):
print((anss[i]))
|
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N, X, Y = LI()
X -= 1
Y -= 1
anss = [0 for i in range(N)]
for i in range(N):
for j in range(i + 1, N):
anss[min(
abs(i - j),
abs(X - i) + 1 + abs(j - Y),
abs(Y - i) + 1 + abs(X - j)
)] += 1
for i in range(1, N):
print((anss[i]))
|
p02726
|
# coding: utf-8
from copy import deepcopy
import sys
sys.setrecursionlimit(100000)
N, X, Y = list(map(int, input().split()))
# from time import time
# start = time()
# neighbor = {}
# for i in range(1, N):
# neighbor[i] = [i+1]
# for i in range(X+4, Y):
# neighbor[i] = [i-1, i+1]
# neighbor[X] = [X+1, Y]
# neighbor[Y] = [Y-1, Y+1]
# neighbor[N] = [] if Y < N else [N-1]
# print(neighbor)
neighbor = {}
for i in range(1, X):
neighbor[i] = [i+1]
for i in range(Y+1, N):
neighbor[i] = [i+1]
for i in range(X+1, Y):
neighbor[i] = [i-1, i+1]
neighbor[X] = [X+1, Y]
neighbor[Y] = [Y-1, Y+1]
neighbor[N] = [] if Y < N else [N-1]
# print(neighbor)
# print(neighbor)
# neighbor = {i: [i-1, i+1] for i in range(2, N)}
# neighbor[1] = [2]
# neighbor[N] = [N-1]
# neighbor[X].append(Y)
# neighbor[Y].append(X)
# appeared_st = set([])
appeared_st = [set([]) for _ in range(N+1)]
# appeared_st[0] = 0
n_k = [0] * N
s_t_dist_dict = {}
# def rec(n, dist, s, k, appeared):
# # print(appeared_st)
# if dist == k:
# # if k == 2:
# # input()
# if s < n and n not in appeared_st[s]:
# appeared_st[s].add(n)
# appeared_st[0] += 1
# # print(appeared_st)
# toes = [node for node in neighbor[n] if node not in appeared]
# for to in toes:
# appeared_copy = deepcopy(appeared)
# appeared_copy.add(to)
# rec(to, dist+1, s, k, appeared_copy)
def rec(n, dist, s, limit, appeared, X, Y):
if s < n:
ke = "{}.{}".format(s, n)
if ke in s_t_dist_dict:
if dist < s_t_dist_dict[ke]:
n_k[s_t_dist_dict[ke]] -= 1
s_t_dist_dict[ke] = dist
n_k[dist] += 1
else:
s_t_dist_dict[ke] = dist
n_k[dist] += 1
# if s < n and n not in appeared_st[s]:
# appeared_st[s].add(n)
# n_k[dist] += 1
# print(appeared_st)
# print(n_k)
# input()
if dist == limit:
return None
if X < n < Y and n - X + 1 > limit - dist:
return None
toes = [node for node in neighbor[n] if node not in appeared]
for to in toes:
appeared_copy = deepcopy(appeared)
appeared_copy.add(to)
rec(to, dist+1, s, limit, appeared_copy, X, Y)
for s in range(1, N):
rec(s, 0, s, N-1, {s}, X, Y)
for k in range(1, N):
print((n_k[k]))
# for k in range(1, N):
# tmp = appeared_st[0]
# for s in range(1, N+1):
# rec(s, 0, s, k, {s})
# print(appeared_st[0] - tmp)
# print(appeared_st)
# print(len(appeared_st))
# print(time() - start)
|
# coding: utf-8
N, X, Y = list(map(int, input().split()))
n_k = [0] * (N+1)
for i in range(1, N):
for j in range(i+1, N+1):
n_k[min(abs(j-i), abs(X-i) + 1 + abs(j-Y))] += 1
for k in range(1, N):
print((n_k[k]))
|
p02726
|
import sys
import itertools
import queue
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7
def read_values(): return list(map(int, input().split()))
def read_index(): return [int(x) - 1 for x in input().split()]
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
class V:
def __init__(self, f, v=None):
self.f = f
self.v = v
def __str__(self):
return str(self.v)
def ud(self, n):
if self.v is None:
self.v = n
else:
self.v = self.f(self.v, n)
def main():
N, X, Y = read_values()
X -= 1
Y -= 1
res = [0] * N
for i in range(N):
q = queue.Queue()
q.put((i, 0))
close = set()
while not q.empty():
s, c = q.get()
if s in close:
continue
close.add(s)
res[c] += 1
if s + 1 < N and s + 1 not in close:
q.put((s + 1, c + 1))
if s > 0 and s - 1 not in close:
q.put((s - 1, c + 1))
if s == X and Y not in close:
q.put((Y, c + 1))
if s == Y and X not in close:
q.put((X, c + 1))
res = [str(l // 2) for l in res[1:]]
print(("\n".join(res)))
if __name__ == "__main__":
main()
|
import sys
import itertools
import queue
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7
def read_values(): return list(map(int, input().split()))
def read_index(): return [int(x) - 1 for x in input().split()]
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
class V:
def __init__(self, f, v=None):
self.f = f
self.v = v
def __str__(self):
return str(self.v)
def ud(self, n):
if self.v is None:
self.v = n
else:
self.v = self.f(self.v, n)
def main():
N, X, Y = read_values()
X -= 1
Y -= 1
res = [0] * N
for i in range(N - 1):
for j in range(i + 1, N):
d = min(
j - i,
abs(X - i) + 1 + abs(Y - j),
abs(Y - i) + 1 + abs(X - j),
)
res[d] += 1
for r in res[1:]:
print(r)
if __name__ == "__main__":
main()
|
p02726
|
n, x, y = list(map(int, input().split()))
lis = []
for i in range(1, n):
for j in range(i+1, n+1):
lis.append(min([j-i, abs(x-i)+1+abs(y-j), abs(y-i)+1+abs(x-j)]))
for i in range(1, n):
print((lis.count(i)))
|
n, x, y = list(map(int, input().split()))
lis = [0]*(n-1)
for i in range(1, n):
for j in range(i+1, n+1):
lis[min([j-i, abs(x-i)+1+abs(y-j), abs(y-i)+1+abs(x-j)])-1] += 1
for i in range(n-1):
print((lis[i]))
|
p02726
|
import queue
def main():
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans = [0]*n
t = [[i+1, i-1] for i in range(n)]
t[x].append(y)
t[y].append(x)
for i in range(n):
for j in range(i+1, n):
if j <= x:
ans[j-i] += 1
elif j <= y:
buf = min(j-i, abs(i-x) + 1 + (y-j))
ans[buf] += 1
else:
buf = min(y-i, abs(x-i)+1)
ans[buf + (j-y)] += 1
for i in range(1, n):
print((ans[i]))
if __name__ == "__main__":
main()
|
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):
ans[min(j-i, abs(x-i)+abs(y-j)+1)] += 1
for v in ans[1:]:
print(v)
if __name__ == "__main__":
main()
|
p02726
|
import sys
read = sys.stdin.read
from itertools import chain
from collections import Counter
def main():
def warshall_floyd(d):
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])
# 更新したdを返す。d[i][j]はノードiからノードjまでの最短距離
# 行きつけないノードはinfになる。
# 負閉路があるなら「ノードvからノードvへのコスト」、つまりd[x][x]がマイナス値になる。
return d
# 入力
n, x, y = list(map(int, input().split()))
# ワーシャルフロイドで更新する変数dをつくる
d = [[float("inf")] * n for _ in range(n)]
d[x - 1][y - 1] = 1
d[y - 1][x - 1] = 1
for i1 in range(n-1):
d[i1][i1+1] = 1
d[i1+1][i1] = 1
for j1 in range(n):
d[j1][j1] = 0
# ワーシャルフロイド実行。
res = warshall_floyd(d)
res1d = chain.from_iterable(res)
res1dc = Counter(res1d)
for i1 in range(1, n):
r = res1dc[i1] // 2
print(r)
if __name__ == '__main__':
main()
|
from collections import defaultdict
def main():
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
klist = defaultdict(int)
for i in range(n):
for j in range(i+1, n):
if (i <= x and j <= x) or (y <= i and y <= j):
k = j - i
klist[k] += 1
elif i <= x and x < j <= y:
k = min(j - i, (x - i + y - j) + 1)
klist[k] += 1
elif i <= x and y <= j:
k = (j - i) - (y - x) + 1
klist[k] += 1
else:
k = min((j - i), ((i - x) + abs(y - j) + 1))
klist[k] += 1
for i1 in range(1, n):
print((klist[i1]))
if __name__ == '__main__':
main()
|
p02726
|
import sys
sys.setrecursionlimit(1000000000)
from collections import Counter
def key(x, y):
return str(x)+str(y)
def main2():
# TLE
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
M = {}
for i in range(N):
for j in range(i, N):
M[key(i, j)] = j - i
def helper(x, y, from_cost):
if 0 <= x <= N-1 and 0 <= y <= N-1:
if M[key(x,y)] > from_cost+1:
M[key(x,y)] = from_cost + 1
cost = from_cost + 1
helper(x-1,y, cost)
helper(x+1,y, cost)
helper(x,y-1, cost)
helper(x,y+1, cost)
helper(X, Y, 0)
cost_list = Counter(list(M.values()))
for k in range(N-1):
print((cost_list[k+1]))
from collections import deque
INF = 1e10
def main():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
ans = [0 for _ in range(N)]
for sv in range(N):
dist = [INF for _ in range(N)]
q = deque([])
def push(v, d):
if dist[v] != INF: return
dist[v] = d
q.append(v)
push(sv, 0)
while q:
sv = q.popleft()
d = dist[sv]
if sv > 0:
push(sv-1, d+1)
if sv < N-1:
push(sv+1, d+1)
if sv == X:
push(Y, d+1)
if sv == Y:
push(X, d+1)
for d in dist:
ans[d] += 1
for k in range(1, N):
print((ans[k] // 2))
main()
|
import sys
sys.setrecursionlimit(1000000000)
from collections import Counter
def key(x, y):
return str(x)+str(y)
def main2():
# TLE
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
M = {}
for i in range(N):
for j in range(i, N):
M[key(i, j)] = j - i
def helper(x, y, from_cost):
if 0 <= x <= N-1 and 0 <= y <= N-1:
if M[key(x,y)] > from_cost+1:
M[key(x,y)] = from_cost + 1
cost = from_cost + 1
helper(x-1,y, cost)
helper(x+1,y, cost)
helper(x,y-1, cost)
helper(x,y+1, cost)
helper(X, Y, 0)
cost_list = Counter(list(M.values()))
for k in range(N-1):
print((cost_list[k+1]))
from collections import deque
INF = 1e10
def main3():
# official TLE
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
ans = [0 for _ in range(N)]
for sv in range(N):
dist = [INF for _ in range(N)]
q = deque([])
def push(v, d):
if dist[v] != INF: return
dist[v] = d
q.append(v)
push(sv, 0)
while q:
sv = q.popleft()
d = dist[sv]
if sv > 0:
push(sv-1, d+1)
if sv < N-1:
push(sv+1, d+1)
if sv == X:
push(Y, d+1)
if sv == Y:
push(X, d+1)
for d in dist:
ans[d] += 1
for k in range(1, N):
print((ans[k] // 2))
def main():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
dist = [0 for _ in range(N)]
for i in range(N-1):
for j in range(i+1, N):
d = min(abs(X-i)+1+abs(j-Y), abs(i-j), abs(Y-i)+1+abs(j-Y))
dist[d] += 1
for k in range(1, N):
print((dist[k]))
main()
|
p02726
|
# D - Line++
def main():
N, X, Y = list(map(int, input().split()))
dist = [0] * N
calc_min_dist = lambda x, y: min(
y - x, abs(X - x) + abs(y - Y) + 1, abs(Y - x) + abs(y - X) + 1
)
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
dist[calc_min_dist(i, j)] += 1
print(("\n".join(map(str, dist[1:]))))
if __name__ == "__main__":
main()
|
# D - Line++
def main():
N, X, Y = list(map(int, input().split()))
dist = [0] * N
calc_min_dist = lambda x, y: min(
y - x, abs(X - x) + abs(y - Y) + 1, abs(Y - x) + abs(y - X) + 1
) # assume x < y
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
dist[calc_min_dist(i, j)] += 1
print(("\n".join(map(str, dist[1:]))))
if __name__ == "__main__":
main()
|
p02726
|
# D - Line++
def main():
N, X, Y = list(map(int, input().split()))
dist_cnt = [0] * N
calc_min_dist = lambda x, y: min(y - x, abs(X - x) + abs(Y - y) + 1) # assume x < y
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
dist_cnt[calc_min_dist(i, j)] += 1
print(("\n".join(map(str, dist_cnt[1:]))))
if __name__ == "__main__":
main()
|
# D - Line++
def main():
N, X, Y = list(map(int, input().split()))
dist_cnt = [0] * N
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
dist_cnt[min(j - i, abs(X - i) + abs(j - Y) + 1)] += 1
print(("\n".join(map(str, dist_cnt[1:]))))
if __name__ == "__main__":
main()
|
p02726
|
n,x,y = list(map(int,input().split()))
arr = [0] * (n-1)
for i in range(1,n):
for j in range(i+1,n+1):
arr[min((j-i),abs(i-x)+1+abs(j-y),abs(i-y)+1+abs(j-x)) - 1] += 1
for i in arr:
print(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):
ans[min((j-i),abs(i-x)+1+abs(j-y),abs(i-y)+1+abs(j-x))-1] += 1
for i in ans:
print(i)
|
p02726
|
#!/usr/bin/env python
# coding: utf-8
# In[18]:
N,X,Y = list(map(int, input().split()))
# In[19]:
for k in range(1,N):
ans = 0
for i in range(1,N+1):
for j in range(i+1,N+1):
dist = min(j-i,abs(X-i)+abs(Y-j)+1,abs(Y-i)+abs(X-j)+1)
if dist == k:
ans += 1
print(ans)
# In[ ]:
|
#!/usr/bin/env python
# coding: utf-8
# In[21]:
N,X,Y = list(map(int, input().split()))
# In[24]:
ans = [0]*N
for i in range(1,N):
for j in range(i+1,N+1):
dist = min(j-i,abs(X-i)+abs(Y-j)+1,abs(Y-i)+abs(X-j)+1)
ans[dist] += 1
for i in range(1,N):
print((ans[i]))
# In[ ]:
|
p02726
|
import sys
import itertools
from collections import Counter
sys.setrecursionlimit(10**6)
def DFS(i,v,d):
global dist
if d > N:
return
# 頂点vに隣接する頂点でvより大きいものが未発見
for u in adj[v]:
# distは最短距離なので上書き禁止
if i != u:
#print(i,u,d)
if dist[i][u] > d:
dist[i][u] = d
dist[u][i] = d
# その先は追加で探索
DFS(i,u,d+1)
N, X, Y = list(map(int, input().split()))
# 隣接リストを作成する
adj = [[] for _ in range(N)]
# adjに入力
for i in range(N-1):
adj[i].append(i+1)
adj[i+1].append(i)
# X,Yをadj入力
adj[X-1].append(Y-1)
adj[Y-1].append(X-1)
# 頂点間の最短距離を保持するdist
dist = [[10**9 for _ in range(N)] for _ in range(N)]
for i in range(N):
DFS(i,i,1)
# print(dist)
# distを1次元化
dist = list(itertools.chain.from_iterable(dist))
c = Counter(dist)
# 結果出力
for k in range(1,N):
print((c[k]//2))
|
N, X, Y = list(map(int, input().split()))
ans = [0] * N
for i in range(N):
for j in range(i+1, N):
tmp = min(j-i, abs(X-1-i) + 1 + abs(Y-1-j))
ans[tmp] += 1
for k in range(1,N):
print((ans[k]))
|
p02726
|
import heapq
def inpl():
return list(map(int, input().split()))
class Graph:
def __init__(self):
self.edge = {}
self.cost = {}
self.vertex = set()
return
def addEdgeCost(self, i, j, c, directed=False):
self.vertex.add(i)
self.vertex.add(j)
if i not in self.edge:
self.edge[i] = []
self.edge[i].append(j)
self.cost[(i, j)] = c
if directed is False:
return
if j not in self.edge:
self.edge[j] = []
self.edge[j].append(i)
self.cost[(j, i)] = c
return
def dijkstra(g: Graph, s=None) -> dict:
def solve(v_start):
ret_cost = {v: float("inf") for v in g.vertex}
ret_cost[v_start] = 0
heap = [(0, v_start)]
while heap:
_, v_from = heapq.heappop(heap)
for v_to in g.edge.get(v_from, []):
nc = ret_cost[v_from] + g.cost[(v_from, v_to)]
if ret_cost[v_to] > nc:
ret_cost[v_to] = nc
heapq.heappush(heap, (nc, v_to))
return ret_cost
if s is None:
V = g.vertex
else:
V = [s]
ret = {}
for v in V:
ret[v] = solve(v)
return ret
N, X, Y = inpl()
G = Graph()
for i in range(N - 1):
G.addEdgeCost(i, i + 1, 1, directed=True)
G.addEdgeCost(X - 1, Y - 1, 1, directed=True)
ans_dict = {}
for g in list(dijkstra(G).values()):
for v in list(g.values()):
ans_dict[v] = ans_dict.get(v, 0) + 1
for i in range(1, N):
print((ans_dict.get(i, 0) // 2))
|
def inpl():
return list(map(int, input().split()))
N, X, Y = inpl()
X -= 1
Y -= 1
ans = {}
for i in range(N):
for j in range(i + 1, N):
c = min(j - i, abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X))
ans[c] = ans.get(c, 0) + 1
for i in range(1, N):
print((ans.get(i, 0)))
|
p02726
|
n,x,y=list(map(int,input().split()))
x+=-1
y+=-1
k=[]
z=0
for i in range(n):
k.append(0)
for i in range(n-1):
for j in range(i+1,n):
z=min(abs(x-i)+1+abs(j-y),abs(x-i)+abs(j-x),abs(y-i)+abs(j-y),j-i)
k[z]+=1
z=0
for i in range(1,n):
print((k[i]))
|
n,x,y=list(map(int,input().split()))
x+=-1
y+=-1
k=[]
z=0
for i in range(n):
k.append(0)
for i in range(n-1):
for j in range(i+1,n):
z=min(abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x),j-i)
k[z]+=1
z=0
for i in range(1,n):
print((k[i]))
|
p02726
|
N,X,Y = list(map(int,input().split()))
cc = []
for i in range(1,N+1):
for j in range(i+1,N+1):
cc.append(min(j-i,abs(X-i)+1+abs(Y-j)))
for i in range(1,N):
print((cc.count(i)))
|
N,X,Y = list(map(int,input().split()))
cc = [0]*(N-1)
for i in range(1,N+1):
for j in range(i+1,N+1):
cc[min(j-i,abs(X-i)+1+abs(Y-j))-1] += 1
for i in cc:
print(i)
|
p02726
|
n,x,y = list(map(int,input().split()))
cnt_l = [0 for i in range(0,n)]
from collections import deque
def bfs(start):
queue = deque()
queue.append([start,0])
isNotSearched = [False]*(n+1)
while(len(queue)>0):
i,cnt = queue.popleft()
if(isNotSearched[i]):
continue
isNotSearched[i]=True
cnt_l[cnt]+=1
pre = (i-1)
nex = (i+1)
if(i==x):
queue.append([y,cnt+1])
if(i==y):
queue.append([x,cnt+1])
if(pre>=1):
queue.append([pre,cnt+1])
if(nex<=n):
queue.append([nex,cnt+1])
for i in range(1,n+1):
bfs(i)
for i in range(1,n):
print((cnt_l[i]//2))
|
n,x,y = list(map(int,input().split()))
cnt_l = [0]*n
from collections import deque
def bfs(start):
queue = deque()
queue.append([start,0])
isSearched = [False]*(n+1)
while(len(queue)>0):
i,cnt = queue.popleft()
if(isSearched[i]):
continue
isSearched[i]=True
cnt_l[cnt]+=1
if(i==x):
nex_l = (i-1,y,i+1)
elif(i==y):
nex_l = (i-1,x,i+1)
else:
nex_l = (i-1,i+1)
for j in nex_l:
if(j < 1 or n < j):
continue
if(isSearched[j]):
continue
queue.append([j,cnt+1])
for i in range(1,n+1):
bfs(i)
for i in range(1,n):
print((cnt_l[i]//2))
|
p02726
|
n,x,y = list(map(int,input().split()))
cnt_l = [0]*n
from collections import deque
def bfs(start):
queue = deque()
queue.append([start,0])
isSearched = [False]*(n+1)
while(len(queue)>0):
i,cnt = queue.popleft()
if(isSearched[i]):
continue
isSearched[i]=True
cnt_l[cnt]+=1
if(i==x):
nex_l = (i-1,y,i+1)
elif(i==y):
nex_l = (i-1,x,i+1)
else:
nex_l = (i-1,i+1)
for j in nex_l:
if(j < 1 or n < j):
continue
if(isSearched[j]):
continue
queue.append([j,cnt+1])
for i in range(1,n+1):
bfs(i)
for i in range(1,n):
print((cnt_l[i]//2))
|
n,x,y = list(map(int,input().split()))
cnt_l = [0]*n
from collections import deque
def bfs(start):
queue = deque()
queue.append(start)
isSearched = [-1]*(n+1)
isSearched[start] = 0
while(len(queue)>0):
i = queue.popleft()
cnt = isSearched[i]
if(i==x):
nex_l = (i-1,y,i+1)
elif(i==y):
nex_l = (i-1,x,i+1)
else:
nex_l = (i-1,i+1)
cnt += 1
for j in nex_l:
if(j < 1 or n < j):
continue
if(isSearched[j]!=-1):
continue
queue.append(j)
isSearched[j] = cnt
cnt_l[cnt] += 1
for i in range(1,n+1):
bfs(i)
for i in range(1,n):
print((cnt_l[i]//2))
|
p02726
|
n,x,y = list(map(int,input().split()))
cnt_l = [0]*n
from collections import deque
def bfs(start):
queue = deque()
queue.append(start)
isSearched = [-1]*(n+1)
isSearched[start] = 0
while(len(queue)>0):
i = queue.popleft()
cnt = isSearched[i]
if(i==x):
nex_l = (i-1,y,i+1)
elif(i==y):
nex_l = (i-1,x,i+1)
else:
nex_l = (i-1,i+1)
cnt += 1
for j in nex_l:
if(j < 1 or n < j):
continue
if(isSearched[j]!=-1):
continue
queue.append(j)
isSearched[j] = cnt
cnt_l[cnt] += 1
for i in range(1,n+1):
bfs(i)
for i in range(1,n):
print((cnt_l[i]//2))
|
n,x,y = list(map(int,input().split()))
cnt_l = [0]*n
from collections import deque
def bfs(start):
queue = deque()
queue.append(start)
isSearched = [-1]*(n+1)
isSearched[start] = 0
while(queue):
i = queue.popleft()
cnt = isSearched[i]
if(i==x):
nex_l = (i-1,y,i+1)
elif(i==y):
nex_l = (i-1,x,i+1)
else:
nex_l = (i-1,i+1)
cnt += 1
for j in nex_l:
if(j < 1 or n < j):
continue
if(isSearched[j]!=-1):
continue
queue.append(j)
isSearched[j] = cnt
cnt_l[cnt] += 1
for i in range(1,n+1):
bfs(i)
for i in range(1,n):
print((cnt_l[i]//2))
|
p02726
|
from collections import Counter
n,x,y=list(map(int,input().split()))
x-=1
y-=1
dist=[]
for i in range(n-1):
for j in range(i+1,n):
dist.append(min(j-i,abs(i-x)+1+abs(j-y)))
c=Counter(dist)
for i in range(1,n):
print((c[i]))
|
n,x,y=list(map(int,input().split()))
x-=1
y-=1
dist=[0 for i in range(n)]
for i in range(n-1):
for j in range(i+1,n):
dist[min(j-i,abs(x-i)+1+abs(y-j))]+=1
for i in dist[1:]:
print(i)
|
p02726
|
# coding: utf-8
import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(eval(input()))
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(eval(input())) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
N, X, Y = LI()
dist = [[INF] * (N+1) for _ in range(N+1)]
for i in range(1, N+1):
for j in range(i, N+1):
dist[i][j] = min(j-i, abs(X-i)+1+abs(Y-j), abs(X-j)+1+abs(Y-i))
for i in range(1, N):
tmp = 0
for d in dist:
tmp += d.count(i)
print(tmp)
|
# coding: utf-8
import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")
N, X, Y = LI()
ans = [0] * N
for i in range(1, N+1):
for j in range(i, N+1):
ans[min(j-i, abs(X-i)+1+abs(Y-j), abs(X-j)+1+abs(Y-i))] += 1
PL(ans[1:])
|
p02726
|
import sys
def input() -> str:
return sys.stdin.readline().rstrip("\r\n")
def main():
def min_dest(a, b):
return min(b-a, abs(x-a)+1+abs(y-b), abs(x-b)+1+abs(y-a))
n, x, y = list(map(int, input().split()))
x, y = x-1, y-1
ans = [0] * (n-1)
for i in range(n):
for j in range(i+1, n):
ans[min_dest(i, j)-1] += 1
for a in ans:
print(a)
if __name__ == "__main__":
main()
|
import sys
def input() -> str:
return sys.stdin.readline().rstrip("\r\n")
def main():
def min_dest(a, b):
return min(b-a, abs(x-a)+1+abs(y-b))
n, x, y = list(map(int, input().split()))
x, y = x-1, y-1
ans = [0] * (n-1)
for i in range(n):
for j in range(i+1, n):
ans[min_dest(i, j)-1] += 1
for a in ans:
print(a)
if __name__ == "__main__":
main()
|
p02726
|
K,X,Y = (int(x) for x in input().split())
num = K*(K-1)/2
distance = [0] *int(num)
ct = 0
for i in range(1,K):
for j in range (i+1,K+1):
distance[ct] = min(j-i,abs(i-X)+abs(j-Y)+1)
ct += 1
for k in range (1,K):
print((distance.count(k)))
|
K,X,Y = (int(x) for x in input().split())
ans = [0] * K
ct = 0
for i in range(1,K):
for j in range (i+1,K+1):
ans[min(j-i,abs(i-X)+abs(j-Y)+1)] += 1
for k in range (1,K):
print((ans[k]))
|
p02726
|
n, x, y = list(map(int, input().split()))
a = []
for s in range(1, n): #start
for g in range(s+1, n+1): #goal
a.append(min(g-s, abs(x-s)+1+abs(g-y), abs(y-s)+1+abs(g-x)))
#print(a)
for i in range(1, n):
print((a.count(i)))
|
n, x, y = list(map(int, input().split()))
a = [0 for i in range(n)]
for s in range(1, n): #start
for g in range(s+1, n+1): #goal
a[min(g-s, abs(x-s)+1+abs(g-y), abs(y-s)+1+abs(g-x))] += 1
#print(a)
for i in range(1, n):
print((a[i]))
|
p02726
|
#6回目、2020-0612
#2重ループ +O(1)
#i,jがループの中か外で場合分け
#初期入力
N, x, y = list(map(int, input().split()))
ans ={i:[]for i in range(1,N)}
for i in range(1,N):
for j in range(i+1,N+1):
#(i,jがループより共に左、ともに右)
if (j <=x or y <=i) :
ans[j-i].append((i,j))
# (iがループより左 and jがループより右)
elif i <=x and y <=j:
ans[x-i +1 +j-y].append((i,j))
# i,jが共にループの中
elif x <i and j <y:
dist =min(j-i,i-x + y-j +1) #時計回りと反時計回りの短いほう、+1はxとyを結んだ部分
ans[dist].append((i,j))
# iがループより左、jがループの中
elif i <=x and j < y:
dist =x-i + min(j-x , y+1-j)
ans[dist].append((i,j))
# iがループの中、jがループの右
elif x <i and y <=j:
dist =min(y-i , 1 +i-x) + j-y
ans[dist].append((i,j))
#答え出力
for i in range(1,N):
print((len(ans[i])))
|
#6回目、2020-0612
#2重ループ +O(1)
#i,jがループの中か外で場合分け
#初期入力
N, x, y = list(map(int, input().split()))
ans ={i:0 for i in range(1,N)}
for i in range(1,N):
for j in range(i+1,N+1):
#(i,jがループより共に左、ともに右)
if (j <=x or y <=i) :
ans[j-i] +=1
# (iがループより左 and jがループより右)
elif i <=x and y <=j:
ans[x-i +1 +j-y] +=1
# i,jが共にループの中
elif x <i and j <y:
dist =min(j-i,i-x + y-j +1) #時計回りと反時計回りの短いほう、+1はxとyを結んだ部分
ans[dist] +=1
# iがループより左、jがループの中
elif i <=x and j < y:
dist =x-i + min(j-x , y+1-j)
ans[dist] +=1
# iがループの中、jがループの右
elif x <i and y <=j:
dist =min(y-i , 1 +i-x) + j-y
ans[dist] +=1
#答え出力
for i in range(1,N):
print((ans[i]))
|
p02726
|
#6回目、2020-0612
#2重ループ +O(1)
#i,jがループの中か外で場合分け
#初期入力
N, x, y = list(map(int, input().split()))
ans ={i:0 for i in range(1,N)}
for i in range(1,N):
for j in range(i+1,N+1):
#(i,jがループより共に左、ともに右)
if (j <=x or y <=i) :
ans[j-i] +=1
# (iがループより左 and jがループより右)
elif i <=x and y <=j:
ans[x-i +1 +j-y] +=1
# i,jが共にループの中
elif x <i and j <y:
dist =min(j-i,i-x + y-j +1) #時計回りと反時計回りの短いほう、+1はxとyを結んだ部分
ans[dist] +=1
# iがループより左、jがループの中
elif i <=x and j < y:
dist =x-i + min(j-x , y+1-j)
ans[dist] +=1
# iがループの中、jがループの右
elif x <i and y <=j:
dist =min(y-i , 1 +i-x) + j-y
ans[dist] +=1
#答え出力
for i in range(1,N):
print((ans[i]))
|
#6回目、2020-0612
#2重ループ +O(1)
#場合分けを近道と通常のみ(絶対値を使う)
#初期入力
N, x, y = list(map(int, input().split()))
normal =0
short =0
ans ={i:0 for i in range(1,N)}
for i in range(1,N):
for j in range(i+1,N+1):
normal =j -i
short =abs(x-i) +1 +abs(j-y)
dist =min(normal,short)
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(1,n):
for j in range(i+1,n+1):
ans[min(min(j-i,abs(x-i)+1+abs(j-y)),abs(y-i)+1+abs(j-x))-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):
ans[min(j-i,abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x))-1]+=1
for i in range(n-1):
print((ans[i]))
|
p02726
|
N,X,Y = list(map(int,input().split()))
def f(i,j):
if j <= X:
return j-i
elif Y <= i:
return j-i
elif X <= i and j <= Y:
return min(j-i,(i-X)+1+(Y-j))
elif i <= X and Y <= j:
return (X-i)+1+(j-Y)
elif i <= X and X <= j and j <= Y:
return (X-i)+min(j-X,1+(Y-j))
else:
return (j-Y)+min(Y-i,(i-X)+1)
A = []
for k in range(1,N,1):
for l in range(k+1,N+1,1):
A.append(f(k,l))
for k in range(1,N,1):
print((A.count(k)))
|
N,X,Y = list(map(int,input().split()))
def f(i,j):
if j <= X:
return j-i
elif Y <= i:
return j-i
elif X <= i and j <= Y:
return min(j-i,(i-X)+1+(Y-j))
elif i <= X and Y <= j:
return (X-i)+1+(j-Y)
elif i <= X and X <= j and j <= Y:
return (X-i)+min(j-X,1+(Y-j))
else:
return (j-Y)+min(Y-i,(i-X)+1)
A = [0]*(N-1)
for k in range(1,N,1):
for l in range(k+1,N+1,1):
A[f(k,l)-1] += 1
for k in range(1,N,1):
print((A[k-1]))
|
p02726
|
n,x,y=list(map(int,input().split()))
dis=[0]*(n-1)
for i in range(1,n):
for j in range(i+1,n+1):
d=min(j-i,min(abs(j-x)+1+abs(i-y),abs(j-y)+1+abs(i-x)))
dis[d-1]+=1
for i in dis:
print(i)
|
n,x,y=list(map(int,input().split()))
dis=[0]*(n-1)
for i in range(1,n):
for j in range(i+1,n+1):
d=j-i
if d>abs(j-x)+1+abs(i-y):
d=abs(j-x)+1+abs(i-y)
if d>abs(j-y)+1+abs(i-x):
d=abs(j-y)+1+abs(i-x)
dis[d-1]+=1
for i in dis:
print(i)
|
p02726
|
from collections import defaultdict
N, X, Y = list(map(int, input().split()))
dic = defaultdict(int)
X = X - 1
Y = Y - 1
for i in range(N):
for j in range(i + 1, N):
if i <= X and Y <= j:
v = X - i + 1 + j - Y
elif (i <= X) and (X <= j and j <= Y):
v = min(j - i, X - i + 1 + Y - j)
elif (X <= i and i <= Y) and Y <= j:
v = min(j - i, i - X + 1 + j - Y)
elif (X <= i and i <= Y) and (X <= j and j <= Y):
v = min(j - i, i - X + 1 + Y - j)
else:
v = j - i
dic[v] += 1
for i in range(1, N):
print((dic[i]))
|
N, X, Y = list(map(int, input().split()))
dic = {}
X = X - 1
Y = Y - 1
for i in range(N):
for j in range(i + 1, N):
if i <= X and Y <= j:
v = X - i + 1 + j - Y
elif (i <= X) and (X <= j and j <= Y):
v = min(j - i, X - i + 1 + Y - j)
elif (X <= i and i <= Y) and Y <= j:
v = min(j - i, i - X + 1 + j - Y)
elif (X <= i and i <= Y) and (X <= j and j <= Y):
v = min(j - i, i - X + 1 + Y - j)
else:
v = j - i
if v in dic:
dic[v] += 1
else:
dic[v] = 1
for i in range(1, N):
if i in dic:
print((dic[i]))
else:
print((0))
|
p02726
|
# D - Line++
from collections import deque
INF = 1001001001
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans = [0]*n
for i in range(n):
dist = [INF]*n
q = deque()
dist[i] = 0
q.append(i)
while len(q)>0:
v = q.popleft()
d = dist[v]
if v-1 >= 0:
if dist[v-1]==INF:
q.append(v-1)
dist[v-1]=d+1
if v+1 < n:
if dist[v+1]==INF:
q.append(v+1)
dist[v+1]=d+1
if v==x:
if dist[y]==INF:
q.append(y)
dist[y]=d+1
if v==y:
if dist[x]==INF:
q.append(x)
dist[x]=d+1
for d in dist:
if d!=0 and d!=INF:
ans[d] += 1
for a in ans[1:]:
print((int(a//2)))
|
# D - Line++
from collections import deque
INF = 1001001001
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans = [0]*n
for i in range(n):
dist = [INF]*n
q = deque()
dist[i] = 0
q.append(i)
while len(q)>0:
v = q.popleft()
d = dist[v]
if v-1 >= 0 and dist[v-1]==INF:
q.append(v-1)
dist[v-1]=d+1
if v+1 < n and dist[v+1]==INF:
q.append(v+1)
dist[v+1]=d+1
if v==x and dist[y]==INF:
q.append(y)
dist[y]=d+1
if v==y and dist[x]==INF:
q.append(x)
dist[x]=d+1
for d in dist:
ans[d] += 1
for a in ans[1:]:
print((int(a//2)))
|
p02726
|
N, X, Y= list(map(int, input().split()))
List=[]
for i in range(1,N+1,1):
for j in range(i,N+1,1):
saitan = min(abs(i-j), abs(i-X)+abs(Y-j)+1, abs(i-Y)+abs(X-j)+1)
List.append(saitan)
for i in range(1,N):
print((List.count(i)))
|
N, X, Y= list(map(int, input().split()))
List=N*[0]
for i in range(1,N+1,1):
for j in range(i,N+1,1):
saitan = min(abs(i-j), abs(i-X)+abs(Y-j)+1, abs(i-Y)+abs(X-j)+1)
List[saitan] += 1
for i in range(1,N):
print((List[i]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
dist_list = []
for i in range(1, N+1):
for j in range(i+1, N+1):
dist_list.append(min([j-i,abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X)]))
for k in range(1,N):
print((dist_list.count(k)))
|
N, X, Y = list(map(int, input().split()))
result = [0]*N
for i in range(1, N+1):
for j in range(i+1, N+1):
result[min([j-i,abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X)])-1]+=1
s = '\n'.join(map(str, result[:-1]))
print(s)
|
p02726
|
import copy
N, X, Y = list(map(int, input().split()))
def check(num, distance):
if num!=0:
distance[num-1]=min(distance[num]+1, distance[num-1])
if num!=N-1:
distance[num+1]=min(distance[num+1], distance[num]+1)
if num==X-1:
distance[Y-1]=min(distance[Y-1], distance[X-1]+1)
elif num==Y-1:
distance[X-1] = min(distance[X-1], distance[Y-1]+1)
total_answer=[]
answer=[N]*N
for k in range(N):
temp=copy.copy(answer)
temp[k]=0
#print(temp)
for i in range(0, N):
check(i, temp)
#print(temp)
#print(temp)
for j in range(N-1,-1,-1):
check(j, temp)
#print(temp)
#print('/n')
for i in range(0, N):
check(i, temp)
for j in range(N - 1, -1, -1):
check(j, temp)
for i in range(0, N):
check(i, temp)
for j in range(N - 1, -1, -1):
check(j, temp)
#print(temp)
#print(temp)
total_answer+=temp
#print(total_answer)
import collections
dict=collections.Counter(total_answer)
#print(dict)
for i in range(1, N):
print((dict[i]//2))
|
N, X, Y=list(map(int, input().split()))
answer=[0]*(N-1)
#i, j from 1 to N
for i in range(1, N):
for j in range(i+1, N+1):
temp=min(abs(j-i), abs(j-Y)+1+abs(X-i)) #, abs(j-X)+1+abs(Y-i)
#print(i, j, temp)
answer[temp-1]+=1
for val in answer:
print(val)
|
p02726
|
from collections import deque
from collections import Counter
n,x,y = list(map(int, input().split()))
x-=1
y-=1
dis=[['NONE']*n for i in range(n)]
d = deque()
for i in range(n):
d.append((i,0))
c=0
while d:
p,j=d.popleft()
if p==x and c==0:
d.append((y,j+1))
c=1
if p==y and c==0:
d.append((x,j+1))
c=1
if dis[i][p]=='NONE':
dis[i][p]=j
if p+1<n:
if dis[i][p+1]=='NONE':
d.append((p+1,j+1))
if p-1>=0:
if dis[i][p-1]=='NONE':
d.append((p-1,j+1))
s=[]
for i in dis:
s+=i
c=Counter(s)
for i in range(1,n):
print((c[i]//2))
|
from collections import Counter
n,x,y = list(map(int, input().split()))
x-=1
y-=1
dis=[]
for i in range(n-1):
for j in range(i,n):
dis.append(min(abs(i-j),abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1))
c=Counter(dis)
for i in range(1,n):
print((c[i]))
|
p02726
|
from collections import deque
n,x,y=list(map(int,input().split()))
x,y=x-1,y-1
e = [[2*10**3+1]*n for _ in range(n)]
for i in range(n):
e[i][i] = 0
def main():
for i in range(n):
s = deque([i]) # サーチstack. 初期条件を設定
dfs(s, e[i])
#print(e)
ans = [0]*n
for i,ee in enumerate(e):
for eee in ee[i:]:
ans[eee] += 1
for i in ans[1:]:
print(i)
def dfs(s,e):
while len(s) > 0: # len(s) > 0 でループ
t = s.popleft()
for i in get_children(t): # t の子ノードを列挙
if e[i] != 2*10**3+1 and e[i] < e[t]+1:
continue
s.append(i)
e[i] = min(e[i], e[t] + 1) # 探索済としつつ距離を入れる
def get_children(t):
if t in (x,y):
yield y if t == x else x
if 0 < t:
yield t-1
if t < (n-1):
yield t+1
if __name__ == "__main__":
main()
|
from collections import Counter
def main():
n,x,y=list(map(int,input().split()))
x,y=x-1,y-1
ans=[]
for i in range(n):
dp = [n]*n
dp[i] = 0
calcstep(i, dp)
dp[y] = min(dp[y], dp[x]+1)
dp[x] = min(dp[x], dp[y]+1)
calcstep(x, dp)
calcstep(y, dp)
#print(i, dp)
ans += dp
ans = Counter(ans)
for i in range(1,n):
print((ans[i]//2))
def calcstep(i, dp):
for j in range(i, len(dp)-1):
if dp[j+1] > dp[j]+1:
dp[j+1] = dp[j]+1
else:
break
for j in range(1,i+1)[::-1]:
if dp[j-1] > dp[j]+1:
dp[j-1] = dp[j]+1
else:
break
if __name__ == "__main__":
main()
|
p02726
|
import queue
N, X, Y = list(map(int, input().split()))
X, Y = X - 1, Y - 1
ans = [0] * (N + 1)
def push(q, dist, index, dist_v):
if dist[index] != -1:
return
q.put(index)
dist[index] = dist_v
for i in range(N):
q = queue.Queue()
dist = [-1] * N
push(q, dist, i, 0)
while not q.empty():
v = q.get()
d = dist[v]
if v - 1 >= 0: push(q, dist, v - 1, d + 1)
if v + 1 < N: push(q, dist, v + 1, d + 1)
if v == X: push(q, dist, Y, d + 1)
if v == Y: push(q, dist, X, d + 1)
for j in range(N):
ans[dist[j]] += 1
for i in range(N):
ans[i] //= 2
for i in range(1, N):
print((ans[i]))
|
from collections import deque
N, X, Y = list(map(int, input().split()))
X, Y = X - 1, Y - 1
ans = [0] * (N + 1)
def push(q, dist, index, dist_v):
if dist[index] != -1:
return
q.appendleft(index)
dist[index] = dist_v
for i in range(N):
q = deque()
dist = [-1] * N
push(q, dist, i, 0)
while len(q) > 0:
v = q.pop()
d = dist[v]
if v - 1 >= 0: push(q, dist, v - 1, d + 1)
if v + 1 < N: push(q, dist, v + 1, d + 1)
if v == X: push(q, dist, Y, d + 1)
if v == Y: push(q, dist, X, d + 1)
for j in range(N):
ans[dist[j]] += 1
for i in range(N):
ans[i] //= 2
for i in range(1, N):
print((ans[i]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
X = X-1
Y = Y-1
for kIndx in range(1, N):
kNum = 0
for jIndx in range(N):
for iIndx in range(jIndx):
if (jIndx <= X) or (iIndx >= Y):
if jIndx - iIndx == kIndx:
kNum += 1
elif (iIndx <= X) and (jIndx >= Y):
if (jIndx - iIndx) - (Y - X -1) == kIndx:
kNum += 1
elif (iIndx <= X) and ((jIndx > X) and (jIndx < Y)):
if 2 * jIndx - (X + Y) - 1 > 0:
if (jIndx - iIndx) - (2 * jIndx - (X + Y) - 1) == kIndx:
kNum += 1
else:
if jIndx - iIndx == kIndx:
kNum += 1
elif ((iIndx > X) and (iIndx < Y)) and (jIndx >= Y):
if (X + Y) - 2 * iIndx - 1 > 0:
if (jIndx - iIndx) - ((X + Y) - 2 * iIndx - 1) == kIndx:
kNum += 1
else:
if jIndx - iIndx == kIndx:
kNum += 1
else:
if (2 * (jIndx - iIndx) - (Y - X) - 1) > 0:
if (jIndx - iIndx) - (2 * (jIndx - iIndx) - (Y - X) - 1) == kIndx:
kNum += 1
else:
if jIndx - iIndx == kIndx:
kNum += 1
print(kNum)
|
N, X, Y = list(map(int, input().split()))
X = X-1
Y = Y-1
kDict = {}
for kIndx in range(1, N+1):
kDict[kIndx] = 0
for jIndx in range(N):
for iIndx in range(jIndx):
if (jIndx <= X) or (iIndx >= Y):
kDict[jIndx - iIndx] += 1
elif (iIndx <= X) and (jIndx >= Y):
kDict[(jIndx - iIndx) - (Y - X - 1)] += 1
elif (iIndx <= X) and ((jIndx > X) and (jIndx < Y)):
if 2 * jIndx - (X + Y) - 1 > 0:
kDict[(jIndx - iIndx) - (2 * jIndx - (X + Y) - 1)] += 1
else:
kDict[jIndx - iIndx] += 1
elif ((iIndx > X) and (iIndx < Y)) and (jIndx >= Y):
if (X + Y) - 2 * iIndx - 1 > 0:
kDict[(jIndx - iIndx) - ((X + Y) - 2 * iIndx - 1)] += 1
else:
kDict[jIndx - iIndx] += 1
else:
if (2 * (jIndx - iIndx) - (Y - X) - 1) > 0:
kDict[(jIndx - iIndx) - (2 * (jIndx - iIndx) - (Y - X) - 1)] += 1
else:
kDict[jIndx - iIndx] += 1
for kIndx in range(1, N):
print((kDict[kIndx]))
|
p02726
|
n, x, y = list(map(int,input().split()))
d = [0 for i in range(1,n)]
for i in range(1,n+1):
for j in range(1,n+1):
if i < j:
d[min([j-i, abs(x-i) + 1 + abs(j-y), abs(y-i) + 1 + abs(j-x)])-1] += 1
for i in d:
print(i)
|
n, x, y = list(map(int,input().split()))
d = [0 for i in range(n-1)]
for i in range(1,n+1):
for j in range(i+1,n+1):
d[min([j-i, abs(x-i) + 1 + abs(j-y), abs(y-i) + 1 + abs(j-x)])-1] += 1
for i in d:
print(i)
|
p02726
|
import math
n, x, y = list(map(int,input().split()))
num = [0 for i in range(n)]
for i in range(n):
for j in range(i+1,n):
num[min([j-i,int(math.fabs(j-y+1))+1+int(math.fabs(i-x+1))])] += 1
for i in range(1,n):
print((num[i]))
|
n, x, y = list(map(int,input().split()))
num = [0 for i in range(n)]
for i in range(1,n+1):
for j in range(i+1,n+1):
ban = min([j-i,abs(x-i)+1+abs(y-j)])
num[ban] += 1
for i in range(1,n):
print((num[i]))
|
p02726
|
n, x, y = list(map(int, input().split()))
dp = [[0 for _ in range(n)] for _ in range(n)]
ans = [0 for _ in range(n-1)]
for i in range(1, n):
for j in range(i+1, n+1):
a = min(j-i, abs(x-i)+abs(y-j)+1, abs(x-j)+abs(y-i)+1)
ans[a-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-1)]
for i in range(1, n):
for j in range(i+1, n+1):
a = min(j-i, abs(x-i)+abs(y-j)+1, abs(x-j)+abs(y-i)+1)
ans[a-1] += 1
for i in range(n-1):
print((ans[i]))
|
p02726
|
from collections import Counter
class Dijkstra():
""" ダイクストラ法
重み付きグラフにおける単一始点最短路アルゴリズム
* 使用条件
- 負のコストがないこと
- 有向グラフ、無向グラフともにOK
* 計算量はO(E*log(V))
* ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい
"""
class Edge():
""" 重み付き有向辺 """
def __init__(self, _to, _cost):
self.to = _to
self.cost = _cost
def __init__(self, V):
""" 重み付き有向辺
無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい
Args:
V(int): 頂点の数
"""
self.G = [[] for i in range(V)] # 隣接リストG[u][i] := 頂点uのi個目の隣接辺
self._E = 0 # 辺の数
self._V = V # 頂点の数
@property
def E(self):
""" 辺数
無向グラフのときは、辺数は有向グラフの倍になる
"""
return self._E
@property
def V(self):
""" 頂点数 """
return self._V
def add(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までの最短路を格納したリストを返す
Args:
s(int): 始点s
Returns:
d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。
到達不可の場合、値はfloat("inf")
"""
import heapq
que = [] # プライオリティキュー(ヒープ木)
d = [float("inf")] * self.V
d[s] = 0
heapq.heappush(que, (0, s)) # 始点の(最短距離, 頂点番号)をヒープに追加する
while len(que) != 0:
cost, v = heapq.heappop(que)
# キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ
if d[v] < cost: continue
for i in range(len(self.G[v])):
# 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する
e = self.G[v][i] # vのi個目の隣接辺e
if d[e.to] > d[v] + e.cost:
d[e.to] = d[v] + e.cost # dの更新
heapq.heappush(que, (d[e.to], e.to)) # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush
return d
n, x, y = [int(i) for i in input().split()]
dij = Dijkstra(n)
for i in range(n-1):
dij.add(i, i+1, 1)
dij.add(x-1, y-1, 1)
d = []
for i in range(n):
d += dij.shortest_path(i)
c = Counter(d)
for i in range(1, n):
print((c[i]//2))
|
from collections import Counter
class Dijkstra():
""" ダイクストラ法
重み付きグラフにおける単一始点最短路アルゴリズム
* 使用条件
- 負のコストがないこと
- 有向グラフ、無向グラフともにOK
* 計算量はO(E*log(V))
* ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい
"""
class Edge():
""" 重み付き有向辺 """
def __init__(self, _to, _cost):
self.to = _to
self.cost = _cost
def __init__(self, V):
""" 重み付き有向辺
無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい
Args:
V(int): 頂点の数
"""
self.G = [[] for i in range(V)] # 隣接リストG[u][i] := 頂点uのi個目の隣接辺
self._E = 0 # 辺の数
self._V = V # 頂点の数
@property
def E(self):
""" 辺数
無向グラフのときは、辺数は有向グラフの倍になる
"""
return self._E
@property
def V(self):
""" 頂点数 """
return self._V
def add(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までの最短路を格納したリストを返す
Args:
s(int): 始点s
Returns:
d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。
到達不可の場合、値はfloat("inf")
"""
import heapq
que = [] # プライオリティキュー(ヒープ木)
d = [float("inf")] * self.V
d[s] = 0
heapq.heappush(que, (0, s)) # 始点の(最短距離, 頂点番号)をヒープに追加する
while len(que) != 0:
cost, v = heapq.heappop(que)
# キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ
if d[v] < cost: continue
for i in range(len(self.G[v])):
# 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する
e = self.G[v][i] # vのi個目の隣接辺e
if d[e.to] > d[v] + e.cost:
d[e.to] = d[v] + e.cost # dの更新
heapq.heappush(que, (d[e.to], e.to)) # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush
return d
n, x, y = [int(i) for i in input().split()]
dij = Dijkstra(n)
for i in range(n-1):
dij.add(i, i+1, 1)
dij.add(x-1, y-1, 1)
c = Counter([])
for i in range(n):
c.update(dij.shortest_path(i))
for i in range(1, n):
print((c[i]//2))
|
p02726
|
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline
n,x,y=list(map(int,input().split()))
dis=[0]*(n-1)
for i in range(1,n+1):
for j in range(1,n+1):
if i>=j: continue
now=min(abs(j-i),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y))
#print(i+1,j+1,now,(abs(j-i),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y)))
dis[now-1]+=1
for i in dis:
print(i)
|
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline
def main():
n,x,y=list(map(int,input().split()))
dis=[0]*(n-1)
for i in range(1,n+1):
for j in range(1,n+1):
if i>=j: continue
now=min(abs(j-i),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y))
#print(i+1,j+1,now,(abs(j-i),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y)))
dis[now-1]+=1
for i in dis:
print(i)
if __name__=="__main__":main()
|
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
def main():
n, x, y = list(map(int, input().split()))
cost = [[float("inf") for i in range(n)] for i in range(n)]
for i in range(n):
if i == n - 1:
tmp_x, tmp_y = x-1, y-1
else:
tmp_x, tmp_y = i, i+1
cost[tmp_x][tmp_y] = 1
cost[tmp_y][tmp_x] = 1
ans_list = [0]*n
for i in range(n):
di_list = dijkstra(i,n,n,cost)
for j in range(i+1,n):
ans_list[di_list[j]] += 1
for i in range(1,n):
print((ans_list[i]))
if __name__ == '__main__':
main()
|
def main():
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans_list = [0]*n
for i in range(n):
for j in range(i,n):
ans_list[min(abs(i-j), abs(i-x)+abs(j-y)+1, abs(j-x)+abs(i-y)+1)] += 1
for i in range(1,n):
print((ans_list[i]))
if __name__ == '__main__':
main()
|
p02726
|
n, x, y = list(map(int,input().split()))
ans = []
for i in range(1,n+1):
for j in range(i+1,n+1):
ans.append(min(j-i,abs(x-i)+1+abs(y-j)))
for k in range(1,n):
print((ans.count(k)))
|
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):
ans[min(j-i,abs(x-i)+1+abs(y-j))-1] += 1
#ans.append(min(j-i,abs(x-i)+1+abs(y-j)))
for k in range(n-1):
print((ans[k]))
|
p02726
|
import sys
from collections import OrderedDict
sys.setrecursionlimit(10 ** 6) # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1 # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n") # リストの要素を改行を挟んで表示する関数
# 入力を整数に変換して受け取る
def input_int():
return int(input())
def map_int_input():
return map(int, input())
MII = map_int_input
def MII_split():
return map(int, input().split())
def MII_to_index():
return map(to_index, input())
def MII_split_to_index():
return map(to_index, input().split())
# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
return list(map(int, input()))
LII = list_int_inputs
def LII_split():
return list(map(int, input().split()))
# 2次元リスト化
def LII_2D(rows_number):
return [LII() for _ in range(rows_number)]
def LII_split_2D(rows_number):
return [LII_split() for _ in range(rows_number)]
N, X, Y = MII_split()
dists = []
for start_node in range(N - 1):
dists_from_start = OrderedDict()
for i in range(start_node, N):
dists_from_start[i] = i - start_node
# if X - 1 >= start_node:
# dists_from_start[Y - 1] = dists_from_start[X - 1] + 1
# for i in range(start_node, N):
# dists_from_start[i] = dists_from_start[Y - 1] + abs(i - (Y - 1))
# else:
back_s = abs(start_node - (X - 1))
for i in range(start_node, N):
dist_t = back_s + 1 + abs(Y - 1 - i)
dists_from_start[i] = min(dist_t, dists_from_start[i])
dists += dists_from_start.values()
for k in range(1, N):
print(dists.count(k))
|
import sys
sys.setrecursionlimit(10 ** 6) # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1 # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n") # リストの要素を改行を挟んで表示する関数
# 入力を整数に変換して受け取る
def input_int():
return int(input())
def map_int_input():
return map(int, input())
MII = map_int_input
def MII_split():
return map(int, input().split())
def MII_to_index():
return map(to_index, input())
def MII_split_to_index():
return map(to_index, input().split())
# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
return list(map(int, input()))
LII = list_int_inputs
def LII_split():
return list(map(int, input().split()))
# 2次元リスト化
def LII_2D(rows_number):
return [LII() for _ in range(rows_number)]
def LII_split_2D(rows_number):
return [LII_split() for _ in range(rows_number)]
N, X, Y = MII_split()
dist_counts = {}
for start_node in range(N - 1):
back_s = abs(start_node - (X - 1))
for i in range(start_node, N):
dist_t = back_s + 1 + abs(Y - 1 - i)
dist = min(dist_t, i - start_node)
if dist in dist_counts:
dist_counts[dist] += 1
else:
dist_counts[dist] = 1
for k in range(1, N):
print(dist_counts[k] if k in dist_counts else 0)
|
p02726
|
#n=int(input())
n,x,y=list(map(int,input().split()))
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
adjl=[[0 for i in range(n)] for j in range(n)]
dic={}
for i in range(n):
for j in range(i,n):
#if i>=j:
# continue
dis=j-i
maybe=abs(x-(i+1))+1+abs(y-(j+1))
dis=min(dis,maybe)
adjl[i][j]=dis
for i in range(n):
for j in range(i,n):
#if i>=j:
# continue
dis=adjl[i][j]
dic[dis]=dic.get(dis,0)+1
for k in range(1,n):
print((dic.get(k,0)))
|
#n=int(input())
n,x,y=list(map(int,input().split()))
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
#adjl=[[0 for i in range(n)] for j in range(n)]
dic={}
for i in range(n):
for j in range(i,n):
#if i>=j:
# continue
dis=j-i
maybe=abs(x-(i+1))+1+abs(y-(j+1))
dis=min(dis,maybe)
#adjl[i][j]=dis
dic[dis]=dic.get(dis,0)+1
for k in range(1,n):
print((dic.get(k,0)))
|
p02726
|
n, x, y = list(map(int, input().split()))
x = x - 1
y = y - 1
kl = [0] * (n - 1)
for s in range(n - 1):
for e in range(s+1, n):
d = e-s
if (e <= x)or(s >= y):
kl[d - 1] += 1
else:
kl[min(d, abs(s-x)+abs(e-y)+1)-1] += 1
for i in kl:
print(i)
|
n, x, y = list(map(int, input().split()))
x = x - 1
y = y - 1
kl = [0] * (n - 1)
for s in range(n - 1):
for e in range(s+1, n):
d = e-s
kl[min(d, abs(s-x)+abs(e-y)+1)-1] += 1
for i in kl:
print(i)
|
p02726
|
import queue
n, x, y = list(map(int, input().split()))
graph = {i: [] for i in range(1, n + 1)}
graph[x].append(y)
graph[y].append(x)
for i in range(1, n):
graph[i].append(i + 1)
graph[i + 1].append(i)
tf = [[False] * (n + 1) for i in range(n + 1)]
ans = [0] * (n + 1)
def bfs(v):
q = queue.Queue()
q.put([v, 0, v])
voi[v] = True
while not q.empty():
sub = q.get()
now = sub[0]
depth = sub[1]
before = sub[2]
if tf[now][v] == False:
ans[depth] += 1
tf[now][v] = True
tf[v][now] = True
for next in graph[now]:
if voi[next]:
continue
voi[next] = True
q.put([next, depth + 1, now])
for i in range(1, n + 1):
voi = [False] * (n + 1)
bfs(i)
for i in range(1, n):
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):
sub = min(abs(j - i), abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x))
ans[sub] += 1
for i in range(1, n):
print((ans[i]))
|
p02726
|
import queue
n,x,y = list(map(int,input().split()))
adj = [[] for i in range(n)]
adj[x-1].append(y-1)
adj[y-1].append(x-1)
for i in range(n-1):
adj[i].append(i+1)
adj[i+1].append(i)
ans = [0 for _ in range(n+1)]
def bfs(start):
inf = 1001001001
q = queue.Queue()
q.put(start)
dist = [inf]*n
dist[start] = 0
while not q.empty():
v = q.get()
for i in adj[v]:
if dist[i] == inf:
dist[i] = dist[v] + 1
q.put(i)
for i in range(n):
ans[dist[i]] += 1
for i in range(n):
bfs(i)
for i in range(1,n):
print((ans[i]//2))
|
from collections import deque
n,x,y = list(map(int,input().split()))
adj = [[] for i in range(n)]
adj[x-1].append(y-1)
adj[y-1].append(x-1)
for i in range(n-1):
adj[i].append(i+1)
adj[i+1].append(i)
ans = [0 for _ in range(n)]
def bfs(start):
inf = 1001001001
q = deque()
q.append(start)
dist = [inf]*n
dist[start] = 0
while q:
v = q.popleft()
for i in adj[v]:
if dist[i] == inf:
dist[i] = dist[v] + 1
q.append(i)
for i in range(n):
ans[dist[i]] += 1
for i in range(n):
bfs(i)
for i in range(1,n):
print((ans[i]//2))
|
p02726
|
n,x,y = list(map(int, input().split()))
import collections
g = [[] for i in range(n)]
for i in range(n):
if i != 0:
g[i].append(i-1)
if i != n-1:
g[i].append(i+1)
g[x-1].append(y-1)
g[y-1].append(x-1)
inf = 10**5
dp = [[inf for i in range(n)] for j in range(n)]
todo = collections.deque()
for i in range(n):
dp[i][i] = 0
for j in g[i]:
todo.append(j)
while len(todo) > 0:
now = todo.popleft()
leng = inf
for j in g[now]:
if dp[i][j] == inf:
todo.append(j)
else:
tem = dp[i][j] + 1
if tem < leng:
leng = tem
dp[i][now] = leng
for i in range(1,n):
ans = 0
for j in range(n):
for k in range(j+1,n):
if dp[j][k] == i:
ans += 1
print(ans)
|
n,x,y = list(map(int, input().split()))
ans = [0]*(n-1)
for j in range(1, n+1):
for i in range(1, j):
dis = min(j-i, abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
ans[dis-1] += 1
for i in ans:
print(i)
|
p02726
|
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 28 20:51:45 2020
@author: naoki
"""
from collections import deque
N, X, Y = list(map(int,input().split()))
distance_count = [0] * (N + 1)
route = [[i-1, i+1] for i in range(N+1)]
del route[-1][-1]
All_distances = [0]*N
route[X].append(Y)
route[Y].append(X)
#%%
for j in range(1,N):
todo = deque([j])
seen = [0 for i in range(N+1)]
distance = [float("inf")] * (N+1)
distance[j] = 0
while len(todo) > 0:
now = todo.pop()
if now == N+1 or now == 0:
continue
for checking in route[now]:
if seen[checking] < 2 and distance[checking] > distance[now] + 1:
distance[checking] = distance[now] + 1
todo.append(checking)
seen[checking] += 1
elif distance[checking] > distance[now] + 1:
distance[checking] = distance[now] + 1
for i in range(j,len(distance)):
if distance[i] != float("inf"):
All_distances[distance[i]] += 1
for i in range(1,N):
print((All_distances[i]))
|
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 28 20:51:45 2020
@author: naoki
"""
from collections import deque
N, X, Y = list(map(int,input().split()))
distance_count = [0] * (N + 1)
route = [[i-1, i+1] for i in range(N+1)]
del route[-1][-1]
All_distances = [0]*N
route[X].append(Y)
route[Y].append(X)
#%%
for j in range(1,N):
todo = deque([j])
seen = [0 for i in range(N+1)]
distance = [N+1] * (N+1)
distance[j] = 0
while len(todo) > 0:
now = todo.pop()
if now == N+1 or now == 0:
continue
for checking in route[now]:
kari1 = distance[checking]
kari2 = distance[now] + 1
if seen[checking] < 2 and kari1 > kari2:
distance[checking] = kari2
todo.append(checking)
seen[checking] += 1
elif kari1 > kari2:
distance[checking] = kari2
for i in range(j,len(distance)):
if distance[i] != N+1:
All_distances[distance[i]] += 1
for i in range(1,N):
print((All_distances[i]))
|
p02726
|
n,x,y = (int(x) for x in input().split())
x-=1
y-=1
middle=(y+x)/2
list=[[0 for i in range(n)]for j in range(n)]
dic={}
for i in range(n-1):
for j in range(i+1,n):
if i<=x and j<=x:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif j==middle:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i==middle:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i<=x and j>=x and j<=middle:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i<=x and j>=middle and j<=y:
k = (x-i) + 1 + (y-j)
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i<=x and j>=middle and j>=y:
k = (x-i) + 1 + (j-y)
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=x and i<=middle and j<=middle:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=x and i<=middle and j>=middle and j<=y:
k = min(j-i, i-x+y-j+1)
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=x and i<=middle and j>=y:
k = i-x + j-y + 1
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=middle and j<=y:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=middle and j>=y:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=y and j>=y:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
for i in range(1,n):
if i not in dic:
print((0))
else:
print((dic[i]))
|
n,x,y = (int(x) for x in input().split())
x-=1
y-=1
middle=(y+x)/2
dic={}
for i in range(n-1):
for j in range(i+1,n):
if i<=x and j<=x:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif j==middle:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i==middle:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i<=x and j>=x and j<=middle:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i<=x and j>=middle and j<=y:
k = (x-i) + 1 + (y-j)
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i<=x and j>=middle and j>=y:
k = (x-i) + 1 + (j-y)
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=x and i<=middle and j<=middle:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=x and i<=middle and j>=middle and j<=y:
k = min(j-i, i-x+y-j+1)
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=x and i<=middle and j>=y:
k = i-x + j-y + 1
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=middle and j<=y:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=middle and j>=y:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
elif i>=y and j>=y:
k = j-i
if k not in dic:
dic[k]=1
else:
dic[k]+=1
for i in range(1,n):
if i not in dic:
print((0))
else:
print((dic[i]))
|
p02726
|
N,X,Y = list(map(int,input().split()))
ans = [0 for i in range(N+1)]
for i in range(1,N):
checking = i
#まずスタート地点から幅優先探索を実装
queue = [[i,0]]
if i >= Y:
checked = list(range(1,i+1))
elif i <= X:
checked = list(range(1,i+1))
else:
checked = list(range(1,X))
checked.append(i)
while(True):
now = queue[0]
#ショートカット確認
if now[0] == X:
if Y not in checked:
queue.append([Y,now[1]+1])
checked.append(Y)
if not(checking > Y):
ans[now[1]+1] += 1
# print(now[0],Y,now[1]+1)
if now[0] == Y:
if X not in checked:
queue.append([X,now[1]+1])
checked.append(X)
if not(checking > X):
ans[now[1]+1] += 1
# print(now[0],X,now[1]+1)
#左
if now[0]-1 >= 1 and now[0]-1 not in checked:
queue.append([now[0]-1,now[1]+1])
checked.append(now[0]-1)
if not(checking > now[0]-1):
ans[now[1]+1] += 1
# print(now[0],now[0]-1,now[1]+1)
#右
if now[0]+1 <= N and now[0]+1 not in checked:
queue.append([now[0]+1,now[1]+1])
checked.append(now[0]+1)
if not(checking > now[0]+1):
ans[now[1]+1] += 1
# print(now[0],now[0]+1,now[1]+1)
queue.pop(0)
if len(checked) == N or len(queue) == 0:
break
#回答を出力
for i in range(1,N):
print((ans[i]))
|
N,X,Y = list(map(int,input().split()))
ans = [0 for i in range(N+1)]
def calc_goal(start,goal):
if goal <= X:
return goal-start
if goal <= Y:
if X >= start:
return min(goal-start,X-start+Y-goal+1)
else:
return min(start-X+Y-goal+1,goal-start)
else:
if X >= start:
return X-start+goal-Y+1
else:
return min(start-X+goal-Y+1,goal-start)
for i in range(1,N):
for j in range(i+1,N+1):
ans[calc_goal(i,j)] += 1
for i in range(1,N):
print((ans[i]))
|
p02726
|
N, X, Y = list(map( int, input().split(" ")))
dlist = []
for i in range(1,N+1):
for j in range(i,N+1):
dis = min( abs(j-i), abs(X-i) +1+abs(j-Y), abs(Y-i) +1+abs(j-X) )
dlist.append(dis)
for i in range(1,N):
cnt = 0
for val in dlist:
if( val == i ):
cnt+=1
print( cnt )
|
N, X, Y = list(map( int, input().split(" ")))
ans = [0]*N
for i in range(1,N+1):
for j in range(i,N+1):
dis = min( abs(j-i), abs(X-i) +1+abs(j-Y), abs(Y-i) +1+abs(j-X) )
ans[dis]+=1
for i in range(1,N):
print(( ans[i] ))
|
p02726
|
N,X,Y=list(map(int,input().split()))
def dist(i,j):
return min([j-i,abs(X-1-i)+1+abs(Y-1-j),abs(Y-1-i)+1+abs(X-1-j)])
dists = []
for i in range(N-1):
for j in range(i+1,N):
dists.append(dist(i,j))
for i in range(1,N):
print((len([str(v) for v in dists if v == i])))
|
N,X,Y=list(map(int,input().split()))
def dist(i,j):
return min([j-i,abs(X-1-i)+1+abs(Y-1-j),abs(Y-1-i)+1+abs(X-1-j)])
dists = {v:0 for v in range(1,N)}
for i in range(N-1):
for j in range(i+1,N):
d = dist(i,j)
dists[d]+=1
for i in range(1,N):
print((dists[i]))
|
p02726
|
n,x,y = list(map(int,input().split()))
ps = []
for i in range(n):
for j in range(i):
ps.append([j+1,i+1])
dists = [0]*(n)
for p in ps:
dist = min(abs(p[0]-p[1]),abs(p[0]-x)+1+abs(p[1]-y),abs(p[1]-x)+1+abs(p[0]-y))
dists[dist] = dists[dist]+1
for i in range(len(dists) - 1):
print((dists[i+1]))
|
n,x,y = list(map(int,input().split()))
dists = [0]*(n)
for i in range(n):
for j in range(i):
dist = min(abs(i-j),abs((i+1)-x)+1+abs((j+1)-y),abs((j+1)-x)+1+abs((i+1)-y))
dists[dist] = dists[dist]+1
for i in range(len(dists) - 1):
print((dists[i+1]))
|
p02726
|
n,x,y = list(map(int,input().split()))
dists = [0]*(n)
for i in range(1,n+1):
for j in range(1,i):
dists[min(abs(i-j),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y))]+=1
for i in range(1,len(dists)):
print((dists[i]))
|
n,x,y = list(map(int,input().split()))
dists = [0]*(n)
for i in range(1,n+1):
for j in range(1,i):
dists[min(i-j,abs(j-x)+1+abs(i-y))]+=1
for i in range(1,len(dists)):
print((dists[i]))
|
p02726
|
# N=頂点数、X,Y=座標
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
# 未セットの値
INF = 10**4
# キューデータ(次の値、最短距離)
queue_list = []
# 最短距離ごとのリスト
min_e_list = [0 for i in range(N)]
for i in range(N):
# キューデータ初期値をセット
queue_list.append([i, 0])
# 最短距離リスト(最短距離)
min_dist_list = [INF for i in range(N)]
# キューデータが空になるまで繰り返す
while(len(queue_list) != 0):
# 先頭データを取り出す。
pop_data = queue_list.pop(0)
# 取り出した座標がセット済みの場合は何もしない
if(min_dist_list[pop_data[0]] != INF):
continue
# 最短距離リストにデータセット
min_dist_list[pop_data[0]] = pop_data[1]
# 2重に数えないよう(i < 取り出した座標時)、最短距離ごとのリストにデータセット
if(i < pop_data[0]):
min_e_list[pop_data[1]] += 1
# 1.隣の頂点(次の座標、+1,-1した値)
if(pop_data[0]+1 < N):
queue_list.append([pop_data[0]+1, pop_data[1]+1])
if(pop_data[0] > 0 and pop_data[0]-1 < N):
queue_list.append([pop_data[0]-1, pop_data[1]+1])
# 2.X,Yで示した値
if(pop_data[0] == X):
queue_list.append([Y, pop_data[1]+1])
if(pop_data[0] == Y):
queue_list.append([X, pop_data[1]+1])
# 出力
for i,v in enumerate(min_e_list):
if(i != 0):
print(v)
|
# N=頂点数、X,Y=座標
N, X, Y = list(map(int, input().split()))
# 最短距離データ
min_dist_list = [0 for i in range(N+1)]
for i in range(1,N+1):
for j in range(i+1, N+1):
t_dist = min(abs(j-i), 1+abs(X-i)+abs(Y-j), 1+abs(Y-i)+abs(X-j))
min_dist_list[t_dist] += 1
for i in range(1, N):
print((min_dist_list[i]))
|
p02726
|
from collections import defaultdict, deque
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()
INF = float('inf')
def bfs(n, g, start):
d = [INF] * n
que = deque([start])
d[start] = 0
while que:
now = que.popleft()
for next in g[now]:
if d[next] != INF:
continue
que.append(next)
d[next] = d[now] + 1
return d
def main():
n, x, y = LI()
edges = defaultdict(list)
edges[x - 1].append(y - 1)
edges[y - 1].append(x - 1)
for i in range(n - 1):
edges[i].append(i + 1)
edges[i + 1].append(i)
ans = [0] * (n - 1)
for i in range(n):
d = bfs(n, edges, i)
for k in range(1, n):
ans[k - 1] += len([j for j in d if j == k])
ans = list(map(lambda x: x//2, ans))
print(*ans, sep='\n')
main()
|
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()
INF = float('inf')
def main():
n, x, y = LI()
x, y = x - 1, y - 1
d = [[INF] * n for _ in range(n)]
ans = [0] * n
for i in range(n - 1):
for j in range(i + 1, n):
d[i][j] = min([j - i,
abs(x - i) + 1 + abs(j - y),
abs(y - i) + 1 + abs(j - x)])
ans[int(d[i][j])] += 1
print(*ans[1:], sep='\n')
main()
|
p02726
|
import math
nums = [int(i) for i in input().split()]
n = nums[0]
x = nums[1]
y = nums[2]
res = {}
for i in range(1, n):
res[i] = 0
for i in range(1, n+1):
for j in range(i+1, n+1):
dis = j - i
disI = min(abs(i-x), abs(i-y))
disJ = min(abs(j-x), abs(j-y))
dis = min(dis, disI+disJ+1)
res[dis] += 1
for i in range(1, n):
print((res[i]))
|
import math
nums = [int(i) for i in input().split()]
n = nums[0]
x = nums[1]
y = nums[2]
res = [0 for i in range(2010)]
for i in range(1, n+1):
for j in range(i+1, n+1):
dis = j - i
dis = min(dis, abs(i-x)+abs(j-y)+1)
res[dis] += 1
for i in range(1, n):
print((res[i]))
|
p02726
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans_l = [0]*n
for i in range(n):
for j in range(i, n):
k = min(abs(j-i), abs(x-i)+1+abs(y-j), abs(x-j)+1+abs(y-i))
ans_l[k] += 1
for ans in ans_l[1:]:
print(ans)
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans_l = [0]*n
def min_dist(a,b):
return min(b-a, abs(x-a)+1+abs(y-b), abs(x-b)+1+abs(y-a))
for i in range(n):
for j in range(i, n):
k = min_dist(i,j)
ans_l[k] += 1
for ans in ans_l[1:]:
print(ans)
|
p02726
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans_l = [0]*n
def min_dist(a,b):
return min(b-a, abs(x-a)+1+abs(y-b), abs(x-b)+1+abs(y-a))
for i in range(n):
for j in range(i, n):
k = min_dist(i,j)
ans_l[k] += 1
for ans in ans_l[1:]:
print(ans)
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans_l = [0]*n
def min_dist(a,b):
return min(b-a, abs(x-a)+1+abs(y-b), abs(x-b)+1+abs(y-a))
for i in range(n):
for j in range(i, n):
ans_l[min_dist(i,j)] += 1
for ans in ans_l[1:]:
print(ans)
|
p02726
|
from heapq import heappush, heappop
n, x, y = list(map(int, input().split()))
links = [[] for i in range(n)]
for i in range(1, n):
links[i-1].append(i)
links[i].append(i-1)
links[x-1].append(y-1)
links[y-1].append(x-1)
ans = [0] * (n+1)
for i in range(n):
dist = [1e5] * n
used = [0] * n
que = []
heappush(que, [0, i])
while len(que):
dis, v = heappop(que)
if used[v]: continue
ans[dis] += 1
used[v] = True
for to in links[v]:
if not used[to]:
heappush(que, [dis+1, to])
for i in range(1, n): print((ans[i]//2))
|
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):
ans[min(j-i, abs(i-x)+1+abs(j-y))] += 1
for i in range(1, n): print((ans[i]))
|
p02726
|
def main():
n, x, y = map(int, input().split())
ans = [0] * (n+1)
d = list()
for i in range(1, n):
for j in range(i+1, n+1):
# x->yを通らない
d1 = abs(j-i)
# i->x->y->jの順 +1はx->yの分
d2 = abs(x-i) + 1 + abs(j-y)
# i->y->x->jの順 +1はy->xの分
d3 = abs(y-i) + 1 + abs(j-x)
dist = min(min(d1, d2), d3)
d.append(dist)
ans[dist] += 1
print(*ans[1:n], sep='\n')
if __name__ == '__main__':
main()
|
def main():
n, x, y = map(int, input().split())
ans = [0] * (n+1)
for i in range(1, n):
for j in range(i+1, n+1):
# x->yを通らない
d1 = abs(j-i)
# i->x->y->jの順 +1はx->yの分
d2 = abs(x-i) + 1 + abs(j-y)
# i->y->x->jの順 +1はy->xの分
d3 = abs(y-i) + 1 + abs(j-x)
dist = min(min(d1, d2), d3)
ans[dist] += 1
print(*ans[1:n], sep='\n')
if __name__ == '__main__':
main()
|
p02726
|
n,x,y = list(map(int,input().split()))
x -= 1
y -= 1
dis = [[0 for i in range(n)]for j in range(n)]
for i in range(n):
for j in range(i+1,n):
dis[i][j] = min(abs(j-i),min(abs(j-y)+abs(x-i)+1,abs(j-x)+abs(y-i)+1))
d = [0 for i in range(n)]
for i in range(n):
for j in range(n):
d[dis[i][j]] += 1
print(("\n".join(map(str,d[1:]))))
|
n,x,y = list(map(int,input().split()))
x -= 1
y -= 1
dis = [0 for i in range(n)]
for i in range(n):
for j in range(i+1,n):
dis[min(abs(j-i),min(abs(j-y)+abs(x-i)+1,abs(j-x)+abs(y-i)+1))] += 1
print(("\n".join(map(str,dis[1:]))))
|
p02726
|
s = input().split()
n=int(s[0])
x=int(s[1])-1
y=int(s[2])-1
inf=float('inf')
map=[]
for i in range(n):
for j in range(i+1,n):
map.append(min(abs(j-i),abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x)))
for i in range(1,n):
print((map.count(i)))
|
s = input().split()
n=int(s[0])
x=int(s[1])-1
y=int(s[2])-1
inf=float('inf')
map={}
for i in range(n):
map[i]=0
for i in range(n):
for j in range(i+1,n):
map[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((map[i]))
|
p02726
|
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()
def main():
N, X, Y = list(map(int, input().split()))
ans = [0] * N
for i in range(1, N+1):
dist = [-1] * (N+1)
dist[i] = 0
q = deque()
q.append(i)
def push(l, m):
if dist[l] > -1:
return
q.append(l)
dist[l] = dist[m] + 1
ans[dist[l]] += 1
while q:
j = q.popleft()
if j < N: push(j+1, j)
if j > 1: push(j-1, j)
if j == X: push(Y, j)
if j == Y: push(X, j)
for i in range(1, N):
print((ans[i]// 2))
if __name__ == '__main__':
main()
|
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()
def main():
N, X, Y = map(int, input().split())
ans = [0] * N
for i in range(1, N+1):
dist = [-1] * (N+1)
dist[i] = 0
q = deque()
q.append(i)
def push(l, m):
if dist[l] > -1:
return
q.append(l)
dist[l] = dist[m] + 1
ans[dist[l]] += 1
while q:
j = q.popleft()
if j < N: push(j+1, j)
if j > 1: push(j-1, j)
if j == X: push(Y, j)
if j == Y: push(X, j)
print(*[i // 2for i in ans[1:]], sep='\n')
if __name__ == '__main__':
main()
|
p02726
|
n,x,y = [int(x) for x in input().split()]
for k in range(1, n):
ans = 0
for i in range(1,n):
for j in range(i+1, n+1):
if min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x)) == k:
ans += 1
print(ans)
|
n,x,y = [int(x) for x in input().split()]
d = {x: 0 for x in range(1, n)}
for i in range(1,n):
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))] += 1
for v in list(d.values()):
print(v)
|
p02726
|
import sys
from heapq import heappush, heappop
inf = float('inf')
n, x, y = list(map(int, sys.stdin.readline().split()))
g = [[] for _ in range(n)]
for i in range(n-1):
g[i].append(i+1)
g[i+1].append(i)
g[x-1].append(y-1)
g[y-1].append(x-1)
def dijkstra(i):
dist = [inf] * n
dist[i] = 0
q = [(0, i)]
visited = set()
while q:
d, x = heappop(q)
if x in visited:
continue
dist[x] = d
visited.add(x)
for y in g[x]:
if y in visited:
continue
heappush(q, (d+1, y))
return dist
def main():
res = [0] * (n + 1)
for i in range(n):
dist = dijkstra(i)
for d in dist:
res[d] += 1
for c in res[1:-1]:
print((c // 2))
if __name__ == "__main__":
main()
|
import sys
from itertools import combinations
n, x, y = list(map(int, sys.stdin.readline().split()))
def main():
res = [0] * (n + 1)
for i, j in combinations(list(range(1, n+1)), 2):
d = min(j - i, abs(i - x) + 1 + abs(j - y))
res[d] += 1
for i in range(1, n):
print((res[i]))
if __name__ == "__main__":
main()
|
p02726
|
N,X,Y = list(map(int, input().split()))
X = X-1
Y = Y-1
kyori = []
for i in range(N):
for j in range(i,N):
l = min(abs(i-j), abs(i-X)+1+abs(j-Y), abs(i-Y)+1+abs(j-X))
kyori.append(l)
for k in range(1,N):
print((kyori.count(k)))
|
N,X,Y = list(map(int, input().split()))
X = X-1
Y = Y-1
kyori = [0]*N
for i in range(N):
for j in range(i+1,N):
l = min(abs(i-j), abs(i-X)+1+abs(j-Y), abs(i-Y)+1+abs(j-X))
kyori[l] += 1
for k in range(1,N):
print((kyori[k]))
|
p02726
|
from collections import deque
n, x, y = list(map(int, input().split()))
g = dict()
for i in range(n):
if i == 0:
g[i] = [i+1]
elif i == n-1:
g[i] = [i-1]
else:
g[i] = [i-1, i+1]
g[x-1].append(y-1)
g[y-1].append(x-1)
distance = [0]*(n-1)
for i in range(n):
queue = deque()
visited = [0]*n
queue.append(i)
while queue:
target = queue.popleft()
for j in g[target]:
if visited[j] == 0 or visited[j] > visited[target] + 1:
visited[j] = visited[target] + 1
queue.append(j)
for k in range(len(visited)):
if k > i:
if visited[k] >= 1:
distance[visited[k]-1] += 1
for l in distance:
print(l)
|
from collections import deque
n, x, y = list(map(int, input().split()))
g = dict()
for i in range(n):
if i == 0:
g[i] = [i+1]
elif i == n-1:
g[i] = [i-1]
else:
g[i] = [i-1, i+1]
g[x-1].append(y-1)
g[y-1].append(x-1)
# print(g)
distance = [0]*(n-1)
# 1番ノードから各ノードへの最短距離を求めていく.
for i in range(n):
queue = deque()
visited = [0]*n
# まず処理される予定のノードが格納されているqueueに最初のノードを格納する
queue.append(i)
while queue:
target = queue.popleft()
for j in g[target]:
if visited[j] == 0 or visited[j] > visited[target] + 1:
visited[j] = visited[target] + 1
queue.append(j)
for k in range(len(visited)):
if k > i:
if visited[k] >= 1:
distance[visited[k]-1] += 1
# print(f"{i}番ノードからの各ノードへの最短距離は{visited}である")
for l in distance:
print(l)
|
p02726
|
from collections import deque
# import sys
# input = sys.stdin.readline
n, x, y = list(map(int, input().split()))
g = dict()
for i in range(n):
if i == 0:
g[i] = [i+1]
elif i == n-1:
g[i] = [i-1]
else:
g[i] = [i-1, i+1]
g[x-1].append(y-1)
g[y-1].append(x-1)
# print(g)
distance = [0]*(n-1)
# 1番ノードから各ノードへの最短距離を求めていく.
for i in range(n):
queue = deque()
visited = [0]*n
# まず処理される予定のノードが格納されているqueueに最初のノードを格納する
queue.append(i)
while queue:
target = queue.popleft()
for j in g[target]:
if visited[j] == 0 or visited[j] > visited[target] + 1:
visited[j] = visited[target] + 1
queue.append(j)
for k, a in enumerate(visited):
if k > i:
if a >= 1:
distance[a-1] += 1
# print(f"{i}番ノードからの各ノードへの最短距離は{visited}である")
for l in distance:
print(l)
|
from collections import deque
def main():
n, x, y = list(map(int, input().split()))
g = dict()
for i in range(n):
if i == 0:
g[i] = [i+1]
elif i == n-1:
g[i] = [i-1]
else:
g[i] = [i-1, i+1]
g[x-1].append(y-1)
g[y-1].append(x-1)
distance = [0]*(n-1)
# 1番ノードから各ノードへの最短距離を求めていく.
for i in range(n):
queue = deque()
visited = [0]*n
# まず処理される予定のノードが格納されているqueueに最初のノードを格納する
queue.append(i)
while queue:
target = queue.popleft()
for j in g[target]:
if visited[j] == 0 or visited[j] > visited[target] + 1:
visited[j] = visited[target] + 1
queue.append(j)
for k, a in enumerate(visited):
if k > i:
if a >= 1:
distance[a-1] += 1
# print(f"{i}番ノードからの各ノードへの最短距離は{visited}である")
for l in distance:
print(l)
if __name__ == "__main__":
main()
|
p02726
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.