input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
n,x,y = list(map(int, input().split()))
list =[]
for i in range(n):
for j in range(i):
b = i+1
a = j+1
if a<=x and b>=y:
list.append(b-y+x-a+1)
elif a>x and b>=y:
d =min(a-x+1,y-a)
list.append(d+b-y)
elif a<=x and b<y:
d =min(b-x,y-b+1)
list.append(x-a+d)
elif a>x and b<y:
list.append(min(b-a,y-b+a-x+1))
else:
list.append(b-a)
for i in range(n-1):
print((list.count(i+1)))
|
n,x,y=list(map(int,input().split()))
ans=[0]*n
list =[]
for i in range(n):
for j in range(i):
b = i+1
a = j+1
if a<=x and b>=y:
k =b-y+x-a+1
elif a>x and b>=y:
d =min(a-x+1,y-a)
k =d+b-y
elif a<=x and b<y:
d =min(b-x,y-b+1)
k =x-a+d
elif a>x and b<y:
k = min(b-a,y-b+a-x+1)
ans[k]+=1
for i in range(1,n):
print((ans[i]))
|
p02726
|
N,X,Y = list(map(int,input().split()))
data = [[3000]*N for _ in range(N)]
for i in range(N-1):
data[i][i+1] = 1
data[i+1][i] = 1
data[i][i] = 0
data[0][0] = 0
data[X-1][Y-1] = 1
data[Y-1][X-1] = 1
for k in range(N):
for i in range(N):
for j in range(N):
data[i][j] = min(data[i][j],data[i][k]+data[k][j])
for i in range(N-1):
counter = 0
for j in range(N):
counter += data[j].count(i+1)
print((int(counter//2)))
|
N,X,Y = list(map(int,input().split()))
a = [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(Y-j),abs(X-j)+1+abs(Y-i))
a[ans -1] += 1
for item in a:
print(item)
|
p02726
|
import heapq
import sys
from collections import defaultdict
input = sys.stdin.readline
def dijkstra_heap(s,edge,n):
#始点sから各頂点への最短距離
d = [10**20] * n
used = [True] * n #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for a,b in edge[s]:
heapq.heappush(edgelist,a*(10**6)+b)
while len(edgelist):
minedge = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge%(10**6)]:
continue
v = minedge%(10**6)
d[v] = minedge//(10**6)
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
return d
def main():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
edge = [[] for _ in range(N)]
for i in range(N-1):
edge[i].append((1,i+1))
edge[i+1].append((1,i))
edge[X].append((1,Y))
edge[Y].append((1,X))
d = []
for i in range(N):
tmp = dijkstra_heap(i, edge, N)
d.append(tmp)
e = defaultdict(int)
for i in range(N):
for j in range(i,N):
if i == j:
continue
e[d[i][j]] += 1
for i in range(1,N):
print((e[i]))
if __name__ == "__main__":
main()
|
def main():
N, X, Y = list(map(int, input().split()))
tree = [[float('inf')] * N for _ in range(N)]
ans = [0] * (N + 1)
X -= 1
Y -= 1
for i in range(N):
for j in range(i,N):
dist = min(j - i, abs(X - i) + 1 + abs(Y - j))
ans[dist] += 1
for i in range(1,N):
print((ans[i]))
if __name__ == "__main__":
main()
|
p02726
|
N, X, Y = list(map(int, input().split(" ")))
counts = [0 for i in range(N-1)]
distances = [[] for i in range(N-1)]
for i in range(N):
for j in range(i+1, N):
dis = j-i
if i <= X-1 :
if j >= Y-1:
dis -= Y-X-1
elif j < Y-1:
dis = min([j-i, (X-1)-i+1+abs(j-(Y-1))])
else:
dis = min([j-i, i-(X-1)+1+abs(j-(Y-1))])
distances[i].append(dis)
for i in range(N-1):
for j in range(N-i-1):
k = distances[i][j]-1
counts[k] += 1
for k in range(N-1):
print((counts[k]))
|
N, X, Y = list(map(int, input().split(" ")))
counts = [0 for i in range(N-1)]
for i in range(N):
for j in range(i+1, N):
if i <= X-1 :
if j >= Y-1:
dis = j-i -(Y-X-1)
elif j < Y-1:
dis = min([j-i, (X-1)-i+1+abs(j-(Y-1))])
else:
dis = min([j-i, i-(X-1)+1+abs(j-(Y-1))])
# distances[i].append(dis)
k = dis-1
counts[k] += 1
for k in range(N-1):
print((counts[k]))
|
p02726
|
from collections import deque
infty = 10 ** 4
def BFS(G, D, u):
queue = deque()
queue.append(u)
visit = [False for k in range(len(D))]
d = 0
L = 1
visit[i] = True
while queue:
add_v = 0
while L > 0:
v = queue.popleft()
D[v] = d
L -= 1
for j in G[v]:
if not visit[j]:
queue.append(j)
visit[j] = True
add_v += 1
d += 1
L = add_v
return D
N, X, Y = list(map(int, input().split()))
G = [[1]]
for i in range(1, N - 1):
G.append([i - 1, i + 1])
G.append([N - 2])
G[X - 1].append(Y - 1)
G[Y - 1].append(X - 1)
dist = [[infty for j in range(N)] for i in range(N)]
for i in range(N):
dist[i] = BFS(G, dist[i], i)
count = [0 for i in range(N)]
for i in range(N):
for j in range(N):
count[dist[i][j]] += 1
for i in range(N - 1):
print((count[i + 1] // 2))
|
N, X, Y = list(map(int, input().split()))
count = [0 for i in range(N)]
dist = [[-1 for j in range(N)] for i in range(N)]
for i in range(N):
for j in range(i + 1, N):
dist[i][j] = min(abs(j - i), abs(X - 1 - i) + 1 + abs(Y - 1 - j))
for i in range(N):
for j in range(i + 1, N):
count[dist[i][j]] += 1
for i in range(1, N):
print((count[i]))
|
p02726
|
import heapq
import sys
def main():
input = sys.stdin.readline
def dijkstra(s,edge):
#始点sから各頂点への最短距離
d = [10**20] * n
used = [True] * n #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for a,b in edge[s]:
heapq.heappush(edgelist,a*(10**6)+b)
while len(edgelist):
minedge = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge%(10**6)]:
continue
v = minedge%(10**6)
d[v] = minedge//(10**6)
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
return d
n,x,y = list(map(int,input().split()))
edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(n-1):
edge[i].append((1,i+1))
edge[i+1].append((1,i))
edge[x-1].append((1,y-1))
edge[y-1].append((1,x-1))
for i in range(n):
edge[i] = tuple(edge[i])
edge = tuple(edge)
ans = [0 for _ in range(n)]
for i in range(n):
#dijkstra(始点,edge)
res = dijkstra(i,edge)
for j in range(i+1,n):
ans[res[j]] += 1
for i in range(1,n):
print((ans[i]))
if __name__ == '__main__':
main()
|
import heapq
import sys
input = sys.stdin.readline
def dijkstra(s,edge):
#始点sから各頂点への最短距離
d = [10**20] * n
used = [True] * n #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for a,b in edge[s]:
heapq.heappush(edgelist,a*(10**6)+b)
while len(edgelist):
minedge = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge%(10**6)]:
continue
v = minedge%(10**6)
d[v] = minedge//(10**6)
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
return d
n,x,y = list(map(int,input().split()))
edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(n-1):
edge[i].append((1,i+1))
edge[i+1].append((1,i))
edge[x-1].append((1,y-1))
edge[y-1].append((1,x-1))
for i in range(n):
edge[i] = tuple(edge[i])
edge = tuple(edge)
ans = [0 for _ in range(n)]
for i in range(n):
#dijkstra(始点,edge)
res = dijkstra(i,edge)
for j in range(i+1,n):
ans[res[j]] += 1
for i in range(1,n):
print((ans[i]))
|
p02726
|
import heapq
import sys
input = sys.stdin.readline
def dijkstra(s,edge):
#始点sから各頂点への最短距離
d = [10**20] * n
used = [True] * n #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for a,b in edge[s]:
heapq.heappush(edgelist,a*(10**6)+b)
while len(edgelist):
minedge = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge%(10**6)]:
continue
v = minedge%(10**6)
d[v] = minedge//(10**6)
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
return d
n,x,y = list(map(int,input().split()))
edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(n-1):
edge[i].append([1,i+1])
edge[i+1].append([1,i])
edge[x-1].append([1,y-1])
edge[y-1].append([1,x-1])
ans = [0 for _ in range(n)]
for i in range(n):
#dijkstra(始点,edge)
res = dijkstra(i,edge)
for j in range(i+1,n):
ans[res[j]] += 1
for i in range(1,n):
print((ans[i]))
|
import heapq
import sys
def main():
input = sys.stdin.readline
def dijkstra(s,edge):
#始点sから各頂点への最短距離
d = [10**20] * n
used = [True] * n #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for a,b in edge[s]:
heapq.heappush(edgelist,a*(10**6)+b)
while len(edgelist):
minedge = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge%(10**6)]:
continue
v = minedge%(10**6)
d[v] = minedge//(10**6)
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
return d
n,x,y = list(map(int,input().split()))
edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(n-1):
edge[i].append((1,i+1))
edge[i+1].append((1,i))
edge[x-1].append((1,y-1))
edge[y-1].append((1,x-1))
for i in range(n):
edge[i] = tuple(edge[i])
edge = tuple(edge)
ans = [0 for _ in range(n)]
for i in range(n):
#dijkstra(始点,edge)
res = dijkstra(i,edge)
for j in range(i+1,n):
ans[res[j]] += 1
for i in range(1,n):
print((ans[i]))
if __name__ == '__main__':
main()
|
p02726
|
INT = lambda: int(eval(input()))
INTM = lambda: list(map(int,input().split()))
STRM = lambda: list(map(str,input().split()))
STR = lambda: str(eval(input()))
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
n,x,y=INTM()
z=y-x
sc=y-x-1
loop=y-x+1
maxl=(n)-(y-x)
for i in range(1,n):
ct=0
if ct==0:
for j in range(1,n):
if j+i<=x or j>=y:
if j+i<=n:
ct+=1
else:
if j<=x:
if j+i+sc<=n:
ct+=1
temp=i-(x-j)
if temp>=2:
if loop>temp*2:
ct+=2
elif loop==temp*2:
ct+=1
else:
ct+=1
else:
lpmin=min(y-j,+(j-x+1))
if lpmin==j-x+1:
if lpmin==y-j:
if lpmin+(n-y)>=i:
ct+=1
else:
if lpmin>i:
ct+=1
elif lpmin==i:
ct+=2
else:
if lpmin+(n-y)>=i:
ct+=1
if loop>i*2:
ct+=2
elif loop==i*2:
ct+=1
else:
if lpmin+(n-y)>=i:
ct+=1
#print(ct)
print(ct)
else:
print(ct)
if __name__ == '__main__':
do()
|
INT = lambda: int(eval(input()))
INTM = lambda: list(map(int,input().split()))
STRM = lambda: list(map(str,input().split()))
STR = lambda: str(eval(input()))
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
n,x,y=INTM()
z=y-x
sc=y-x-1
loop=y-x+1
maxl=n-(y-x)+loop//2+1
for i in range(1,n):
ct=0
if i<maxl:
for j in range(1,n):
if j+i<=x or j>=y:
if j+i<=n:
ct+=1
else:
if j<=x:
if j+i+sc<=n:
ct+=1
temp=i-(x-j)
if temp>=2:
if loop>temp*2:
ct+=2
elif loop==temp*2:
ct+=1
else:
ct+=1
else:
lpmin=min(y-j,+(j-x+1))
if lpmin==j-x+1:
if lpmin==y-j:
if lpmin+(n-y)>=i:
ct+=1
else:
if lpmin>i:
ct+=1
elif lpmin==i:
ct+=2
else:
if lpmin+(n-y)>=i:
ct+=1
if loop>i*2:
ct+=2
elif loop==i*2:
ct+=1
else:
if lpmin+(n-y)>=i:
ct+=1
#print(ct)
print(ct)
else:
print(ct)
if __name__ == '__main__':
do()
|
p02726
|
n, x, y = list(map(int, input().split()))
ans = [0 for i in range(n-1)]
for i in range(n-1):
for j in range(i+1, n):
k = i + 1
l = j + 1
a = l - k
b_1 = k - x
b_2 = l - y
c_1 = k - y
c_2 = l - x
if b_1 < 0:
b_1 = - b_1
if b_2 < 0:
b_2 = - b_2
if c_1 < 0:
c_1 = - c_1
if c_2 < 0:
c_2 = - c_2
b = b_1 + b_2 + 1
c = c_1 + c_2 + 1
if b < a:
a = b
if c < a:
a = c
ans[a-1] += 1
for i in ans:
print(i)
|
n, x, y = list(map(int, input().split()))
ans = [0 for i in range(n-1)]
for i in range(n-1):
k = i + 1
b_1 = k - x
c_1 = k - y
if b_1 < 0:
b_1 = - b_1
if c_1 < 0:
c_1 = - c_1
for j in range(i+1, n):
l = j + 1
a = l - k
b_2 = l - y
c_2 = l - x
if b_2 < 0:
b_2 = - b_2
if c_2 < 0:
c_2 = - c_2
b = b_1 + b_2 + 1
c = c_1 + c_2 + 1
if b < a:
a = b
if c < a:
a = c
ans[a-1] += 1
for i in range(n-1):
print((ans[i]))
|
p02726
|
n, x, y = list(map(int, input().split()))
ans = [0 for i in range(n-1)]
for i in range(n-1):
k = i + 1
b_1 = k - x
if b_1 < 0:
b_1 = - b_1
for j in range(i+1, n):
l = j + 1
a = l - k
b_2 = l - y
if b_2 < 0:
b_2 = - b_2
b = b_1 + b_2 + 1
if b < a:
a = b
ans[a-1] += 1
for i in range(n-1):
print((ans[i]))
|
n, x, y = list(map(int, input().split()))
ans = [0 for i in range(n-1)]
for i in range(n-1):
k = i + 1
b_1 = k - x
for j in range(i+1, n):
l = j + 1
a = l - k
b = abs(k - x) + abs(l - y) + 1
if b < a:
a = b
ans[a-1] += 1
for i in range(n-1):
print((ans[i]))
|
p02726
|
n, x, y = list(map(int, input().split()))
ans = [0 for i in range(n-1)]
for i in range(n-1):
k = i + 1
b_1 = k - x
for j in range(i+1, n):
l = j + 1
a = l - k
b = abs(k - x) + abs(l - y) + 1
if b < a:
a = b
ans[a-1] += 1
for i in range(n-1):
print((ans[i]))
|
n, x, y = list(map(int, input().split()))
ans = [0 for i in range(n-1)]
for i in range(n-1):
k = i + 1
b_1 = k - x
for j in range(i+1, n):
l = j + 1
a = l - k
b = abs(k - x) + abs(l - y) + 1
if b < a:
ans[b-1] += 1
else:
ans[a-1] += 1
for i in range(n-1):
print((ans[i]))
|
p02726
|
[N, X, Y] = [int(item) for item in input().split()]
X -= 1
Y -= 1
array=[[-1 for _ in range(N)]for _ in range(N)]
for i in range(N):
for j in range(i,N):
array[i][j]=min(abs(i-j),abs(i-X)+1+abs(Y-j),abs(i-Y)+1+abs(X-j))
#print(array)
count=[0 for _ in range(N)]
for i in range(N):
for j in range(i,N):
count[array[i][j]]+=1
for i in range(1,N):
print((count[i]))
#print(count)
|
[N, X, Y] = [int(item) for item in input().split()]
X -= 1
Y -= 1
count=[0 for _ in range(N)]
for i in range(N):
for j in range(i,N):
count[min(abs(i-j),abs(i-X)+1+abs(Y-j),abs(i-Y)+1+abs(X-j))]+=1
#print(array)
for i in range(1,N):
print((count[i]))
#print(count)
|
p02726
|
n,x,y = list(map(int,input().split()))
mn_ln = [[0 for _ in range(n-1)] for _ in range(n)]
dic = {}
x = x-1
y = y-1
for i in range(n):
for j in range(n):
if(i == j):
break
nm = abs(j - i)
if(abs(x-i) > abs(y-i)):
lp = abs(y-i) + abs(x-j) + 1
else:
lp = abs(x-i) + abs(y-j) + 1
k = min(nm,lp)
if(k in dic):
dic[k] += 1
else:
dic[k] = 1
#print(dic[2])
for i in range(1,n):
if not (i in dic):
print((0))
else:
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(n):
if(i == j):
break
nm = abs(j - i)
if(abs(x-i) > abs(y-i)):
lp = abs(y-i) + abs(x-j) + 1
else:
lp = abs(x-i) + abs(y-j) + 1
k = min(nm,lp)
if(k in dic):
dic[k] += 1
else:
dic[k] = 1
for i in range(1,n):
if not (i in dic):
print((0))
else:
print((dic[i]))
|
p02726
|
# coding: utf-8
# Your code here!
#保存
import heapq
import sys
import itertools
sys.setrecursionlimit(10**7)
def bfs(cost,node):
root[node]=min(root[node],cost)
visited[node]=1
for next_n in way[node]:
if visited[next_n]==0:
heapq.heappush(q,[cost+1,next_n])
return
N,X,Y=list(map(int,input().split()))
r=[i for i in range(N)]
way=[[] for i in range(N)]
for i in range(N-1):
way[i].append(i+1)
way[i+1].append(i)
way[X-1].append(Y-1)
way[Y-1].append(X-1)
#print(way)
made=[]
#print(q)
for start in r:
root=[10**9]*N
visited=[0]*N
#print(root)
q=[[0,start]]
heapq.heapify(q)#costとnode
while q:
temp=heapq.heappop(q)
#print(temp)
#print(temp)
if visited[temp[1]]==0:
bfs(temp[0],temp[1])
made.append(root)
#print(made)
ans=[0]*(N)
for item in made:
for num in item:
ans[num]+=1
for a in ans[1:]:
print((a//2))
"""
ans=10**9
for order in itertools.permutations([i for i in range(len(r))]):
#print(order)
temp=0
for i in range(len(order)-1):
fro=r[order[i]]
aft=r[order[i+1]]
#print("YES")
#print(order[i]-1,order[i+1]-1)
#print(root[order[i]-1][0])
temp+=abs(made[order[i]][aft-1]-made[order[i]][fro-1])
ans=min(ans,temp)
print(ans)
"""
|
# coding: utf-8
# Your code here!
N,X,Y=list(map(int,input().split()))
X-=1
Y-=1
ans=[0]*N
for n in range(N-1):
for tgt in range(n+1,N):
temp=min(abs(tgt-n),abs(n-X)+abs(Y-tgt)+1)
#print(n,tgt,temp)
ans[temp]+=1
for a in ans[1:]:
print(a)
|
p02726
|
INF = float('inf')
N, X, Y = list(map(int, input().split()))
G = [[0 if i == j else INF for j in range(N)] for i in range(N)]
for i in range(N-1):
G[i][i+1] = G[i+1][i] = 1
G[X-1][Y-1] = G[Y-1][X-1] = 1
for k in range(N):
for i in range(N):
for j in range(N):
G[i][j] = min(G[i][j], G[i][k] + G[k][j])
for k in range(1, N):
rk = 0
for i in range(N):
for j in range(N):
if j <= i: continue
if G[i][j] == k:
rk += 1
print(rk)
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
R = [0 for j in range(N)]
for i in range(N-1):
for j in range(N):
if j <= i:
continue
xd = abs(i - X)
yd = abs(j - Y)
dist = min(
j - i,
xd + yd + 1
)
R[dist] += 1
for r in R[1:]:
print(r)
|
p02726
|
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return list(map(int,input().split()))
def onem(): #Nとかの取得
return int(eval(input()))
def s(x): #圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(list(map(max,x)))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
"""
def nibu(x,n,r):
ll = 0
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if (ここに評価入れる):
rr = mid
else:
ll = mid+1
"""
import heapq
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 warshall_floyd(n,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])
return d
n,x,y = m()
dp = [[mod for i in range(n)] for j in range(n)]
for i in range(n):
dp[i][i] = 0
for i in range(n-1):
dp[i][i+1] = 1
for i in range(1,n):
dp[i][i-1] = 1
dp[x-1][y-1] = 1
dp[y-1][x-1] = 1
po = dijkstra(x-1,n,n,dp)
ppo = dijkstra(y-1,n,n,dp)
ans = [0 for i in range(n)]
ppp = warshall_floyd(n,dp)
for i in range(n):
for j in range(n):
on = min(dp[i][j],po[i]+po[j],ppo[i]+ppo[j],po[i]+ppo[j] + 1,ppo[i]+po[j] + 1)
#print(i,j,on)
#print(ppp[i][j])
ans[on] += 1
for i in range(1,n):
print((ans[i]//2))
|
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return list(map(int,input().split()))
def onem(): #Nとかの取得
return int(eval(input()))
def s(x): #圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(list(map(max,x)))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
"""
def nibu(x,n,r):
ll = 0
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if (ここに評価入れる):
rr = mid
else:
ll = mid+1
"""
import heapq
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 warshall_floyd(n,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])
return d
n,x,y = m()
dp = [[mod for i in range(n)] for j in range(n)]
for i in range(n):
dp[i][i] = 0
for i in range(n-1):
dp[i][i+1] = 1
for i in range(1,n):
dp[i][i-1] = 1
dp[x-1][y-1] = 1
dp[y-1][x-1] = 1
po = dijkstra(x-1,n,n,dp)
ppo = dijkstra(y-1,n,n,dp)
ans = [0 for i in range(n)]
for i in range(n):
for j in range(n):
on = min(abs(i-j),po[i]+po[j],ppo[i]+ppo[j],po[i]+ppo[j] + 1,ppo[i]+po[j] + 1)
#print(i,j,on)
#print(ppp[i][j])
ans[on] += 1
for i in range(1,n):
print((ans[i]//2))
|
p02726
|
from collections import deque
n, x, y = list(map(int, input().split()))
inf = 100100100
x -= 1
y -= 1
ans = [0] * n
for i in range(n):
dist = [inf] * n
queue = deque()
queue.append(i)
dist[i] = 0
while queue:
current = queue.popleft()
d = dist[current]
if current - 1 >= 0 and dist[current - 1] == inf:
queue.append(current - 1)
dist[current - 1] = d + 1
if current + 1 < n and dist[current + 1] == inf:
queue.append(current + 1)
dist[current + 1] = d + 1
if current == x and dist[y] == inf:
queue.append(y)
dist[y] = d + 1
if current == y and dist[x] == inf:
queue.append(x)
dist[x] = d + 1
for j in range(n):
ans[dist[j]] += 1
for k in range(1, n):
print((ans[k] // 2))
|
from collections import deque, Counter
n, x, y = list(map(int, input().split()))
inf = 100100100
x -= 1
y -= 1
ans = [0] * n
for i in range(n):
dist = [inf] * n
queue = deque()
queue.append(i)
dist[i] = 0
while queue:
current = queue.popleft()
d = dist[current]
if current - 1 >= 0 and dist[current - 1] == inf:
queue.append(current - 1)
dist[current - 1] = d + 1
if current + 1 < n and dist[current + 1] == inf:
queue.append(current + 1)
dist[current + 1] = d + 1
if current == x and dist[y] == inf:
queue.append(y)
dist[y] = d + 1
if current == y and dist[x] == inf:
queue.append(x)
dist[x] = d + 1
for j in range(n):
ans[dist[j]] += 1
for k in range(1, n):
print((ans[k] // 2))
|
p02726
|
# D
# -*- coding: utf-8 -*-
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
ans_list = [[-1 for _ in range(N)] for _ in range(N)]
for i in range(N - 1):
for j in range(i + 1, N):
# ans_list[i][j] = min(abs(j - i), abs(X - i) + 1 + abs(j - Y))
ans_list[i][j] = min(abs(j - i), abs(X - i) + 1 + abs(j - Y))
for i in range(1, N):
ans = 0
for j in range(N):
ans += ans_list[j].count(i)
print(ans)
|
# D
# -*- coding: utf-8 -*-
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
ans_list = [0 for _ in range(N)]
for i in range(N - 1):
for j in range(i + 1, N):
ans_list[min(abs(j - i), abs(X - i) + 1 + abs(j - Y))] += 1
for i in range(1, N):
print((ans_list[i]))
|
p02726
|
n, x, y = [int(i) for i in input().split()]
ans = [0]*n
for i in range(n-1):
for j in range(i+1, n):
ans[min(j-i, abs(x-(i+1))+abs((j+1)-y)+1)] += 1
print(*ans[1:], sep='\n')
|
n, x, y = [int(i) for i in 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(j-y)+1)] += 1
print(*ans[1:], sep='\n')
|
p02726
|
import heapq
def set_heapq(que, edge, used, v, add_dist=0):
'''
確定地点vからつながる辺を全てqueに設定し、返却する
Parameters
que : heapque(touple or list)
辺を管理するキュー (距離、次の行き先)のtopuleまたはlistにて管理
edge : list
全ての辺を格納する二次元のリスト edge[0]にてノード0から伸びる辺であることを表し、
edge[0] → [距離、次の行き先] を表すlistが格納されている
v : int
グラフ上のノード ダイクストラでは確定したノードがvにあたる
add_dist : int
確定した地点に足し合わせる距離 スタート地点以外では何かしらの値が追加されることになる
Returns
que : heapque(touple or list)
引数queにvからつながる辺を追加したキュー
'''
for a,b in edge[v]:
if used[b]:
heapq.heappush(que,(a+add_dist,b))
return que
def dijkstra_heap(n, s, edge):
'''
ダイクストラ法でsで指定された地点からの全てのノードまでの最短距離を返却
Parameters
n : int
ノードの数
s : int
スタート地点
edge : list
全ての辺を格納する二次元のリスト edge[0]にてノード0から伸びる辺であることを表し、
edge[0] → [距離、次の行き先] を表すlistが格納されている
Returns
d : list
スタート地点から全てのノードの最短距離のリスト
'''
d = [float("inf")] * n
used = [True] * n #True:未確定
d[s], used[s] = 0, False
edgelist = set_heapq([], edge, used, s)
while len(edgelist):
a, b = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[b]:
continue
d[b], used[b] = a, False
# 確定地点vからつながる辺を全て優先度付きキューに入れる
edgelist = set_heapq(edgelist, edge, used, b, d[b])
return d
N, X, Y = list(map(int, input().split()))
X, Y = X-1, Y-1
edge = [[] for _ in range(N)]
for i in range(N-1):
x, y = i, i+1
edge[x].append((1, y))
edge[y].append((1, x))
edge[X].append((1, Y))
edge[Y].append((1, X))
tmp = []
for i in range(N):
tmp.append(dijkstra_heap(N, i, edge))
#print(tmp)
ans = []
for i in range(N):
for j in range(i+1,N):
ans.append(tmp[i][j])
from collections import Counter
c = Counter(ans)
for i in range(1, N):
print((c[i]))
|
from itertools import combinations
from collections import Counter
N, X, Y = list(map(int, input().split()))
X, Y = X-1, Y-1
ans = []
for i, j in combinations(list(range(N)), 2):
ans.append(min(j-i, 1+abs(i-X)+abs(j-Y)))
c = Counter(ans)
for i in range(1,N):
print((c[i]))
|
p02726
|
import sys
from itertools import combinations
from collections import Counter
N, X, Y = list(map(int, sys.stdin.readline().rstrip().split()))
nodes = list(range(1, N + 1))
distance_counter = Counter()
a = Y - X - 1
p = (Y - X) // 2 + X
ans = []
for i, j in combinations(nodes, 2):
if j - i == 1:
continue
distance = min(abs(X - i) + abs(Y - j) + 1, j - i)
distance_counter[distance] += 1
for k in range(1, N):
if k == 1:
ans.append(N)
else:
ans.append(distance_counter.get(k, 0))
print(('\n'.join(map(str, ans))))
|
import sys
N, X, Y = list(map(int, sys.stdin.readline().rstrip().split()))
nodes = list(range(1, N + 1))
ans = [0] * N
for i in range(1, N):
for j in range(i + 2, N + 1):
distance = min(abs(X - i) + abs(Y - j) + 1, j - i)
ans[distance] += 1
for k in range(1, N):
if k == 1:
print(N)
else:
print((ans[k]))
|
p02726
|
N,X,Y = list(map(int,input().split()))
ans = [0] * (N-1)
for i in range(1,N+1):
for j in range(1,N+1):
if i != j:
min_distance = min(abs(i-j), abs(i-X)+abs(j-Y)+1, abs(j-X)+abs(i-Y)+1)
ans[min_distance-1] += 1
for i in range(N-1):
print((int(ans[i]/2)))
|
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):
min_distance = min(abs(i-j), abs(i-X)+abs(j-Y)+1, abs(j-X)+abs(i-Y)+1)
ans[min_distance-1] += 1
for i in range(N-1):
print((ans[i]))
|
p02726
|
n,x,y=list(map(int,input().split()))
ans=[[1000000]*n for i in range(n)]
for i in range(n-1):
for j in range(i+1,n):
ans[i][j]=min(j-i,abs(x-1-i)+1+abs(y-1-j))
_ans=[0]*(n-1)
for i in range(n-1):
for j in range(i+1,n):
_ans[ans[i][j]-1]+=1
for i in range(n-1):
print((_ans[i]))
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
out = [0] * N
for i in range(N-1):
for j in range(i+1, N):
out[min(j-i, abs(i-X)+1+abs(j-Y))] += 1
for i in range(1, N):
print((out[i]))
|
p02726
|
from collections import deque
n, x, y = list(map(int, input().split()))
graph = [[i-1,i+1] for i in range(n+1)]
graph[1]=[2]
graph[n]=[n-1]
graph[0]=[0]
graph[x].append(y)
graph[y].append(x)
def bfs(start,graph2):
dist = [-1] * (n+1)
dist[0] = 0
dist[start] = 0
d = deque()
d.append(start)
while d:
v = d.popleft()
for i in graph2[v]:
if dist[i] != -1:
continue
dist[i] = dist[v] + 1
d.append(i)
dist = dist[start+1:]
return dist
ans = [0]*n
for j in range(1,n):
dist = bfs(j,graph)
for k in range(1,n):
ans[k] += dist.count(k)
for x in range(1,n):
print((ans[x]))
|
from collections import deque
n, x, y = list(map(int, input().split()))
graph = [[i-1,i+1] for i in range(n+1)]
graph[1]=[2]
graph[n]=[n-1]
graph[0]=[0]
graph[x].append(y)
graph[y].append(x)
def bfs(start,graph2):
dist = [-1] * (n+1)
dist[0] = 0
dist[start] = 0
d = deque()
d.append(start)
while d:
v = d.popleft()
for i in graph2[v]:
if dist[i] != -1:
continue
dist[i] = dist[v] + 1
d.append(i)
dist = dist[start+1:]
return dist
ans=[0 for _ in range(n-1)]
for i in range(1,n+1):
for j in bfs(i,graph):
ans[j-1] +=1
for i in ans:
print(i)
|
p02726
|
from collections import Counter
n,x,y = list(map(int, input().split()))
x -= 1
y -= 1
ans = [0]*n
dp = [[0]*n for _ in range(n)]
for i in range(n):
for j in range(n):
ans[min(abs(i-j),(abs(i-x)+abs(j-y)+1),(abs(i-y)+abs(j-x)+1))]+=1
for k in range(1,n):
print((ans[k]//2))
|
from collections import Counter
n,x,y = list(map(int, input().split()))
x -= 1
y -= 1
ans = [0]*n
dp = [[0]*n for _ in range(n)]
for i in range(n):
for j in range(i,n):
ans[min(abs(i-j),(abs(i-x)+abs(j-y)+1),(abs(i-y)+abs(j-x)+1))]+=1
for k in range(1,n):
print((ans[k]))
|
p02726
|
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
N,X,Y = list(map(int, input().split()))
edges = [[] for _ in range(N)]
for i in range(N-1):
edges[i].append(i+1)
edges[i+1].append(i)
edges[X-1].append(Y-1)
edges[Y-1].append(X-1)
ans = [0] * (N-1)
queue = deque([])
def bfs(start):
queue.extend(edges[start])
visited = [False] * N
visited[start] = True
i = 0
while queue:
length = len(queue)
for l in range(length):
current = queue.popleft()
if not visited[current]:
ans[i] += 1
if edges[current]:
queue.extend(edges[current])
visited[current] = True
i += 1
for i in range(N):
bfs(i)
for i in ans:
print((i // 2))
|
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
N,X,Y = list(map(int, input().split()))
queue = deque()
edges = [[] for _ in range(N)]
for i in range(N-1):
edges[i].append(i+1)
edges[i+1].append(i)
edges[X-1].append(Y-1)
edges[Y-1].append(X-1)
ans = [0] * N
for i in range(N):
visited = [0] * N
visited[i] = 1
queue.append((i,0))
while queue:
current, dist = queue.popleft()
ans[dist] += 1
for e in edges[current]:
if visited[e] != 1:
queue.append((e, dist+1))
visited[e] = 1
ans = ans[1:]
for a in ans:
print((a//2))
|
p02726
|
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
nx = j + dx; ny = i + dy
if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)
def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline()) # SingleInt
def ss(): return eval(input())
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)] # HeightString
def s_list(): return list(eval(input()))
def mi(n): return [wi() for _ in range(n)] # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
0]] for _ in range(n)] # NumberGrid
def grid(n): return [s_list() for _ in range(n)]
def gcd(a, b):
while b:
a, b = b, a % b
return a
# a/b の切り上げ
def round_up(a, b):
""" a/b の切り上げ """
c = (a + b - 1) / b
return c
def lcm(a, b):
"""a,bの最小公倍数"""
return a * b // gcd(a, b)
def main():
n, x, y = list(map(int, input().split()))
ans = [0] * n
for i in range(1, n+1):
for j in range(i+1, n+1):
a = min(abs(x-i)+1+abs(j-y), abs(j-i))
ans[a] += 1
for i in range(1, len(ans)):
print((ans[i]))
if __name__ == '__main__':
main()
|
N, X, Y = list(map(int, input().split()))
ans = [0]*N
for i in range(1, N):
for j in range(i+1, N+1):
d = min(j - i, abs(X - i) + 1 + abs(Y - j))
ans[d] += 1
for i in range(1, N):
print((ans[i]))
|
p02726
|
from collections import defaultdict, deque
N, X, Y = list(map(int, input().split()))
G = defaultdict(list)
for i in range(1, N):
G[i].append(i+1)
G[i+1].append(i)
#print(G)
G[X].append(Y)
G[Y].append(X)
#print(G)
d = [0] * N
for i in range(1, N+1):
q = deque()
q.append(i)
visit = [-1]*N
visit[i-1] = 0
while q:
p = q.popleft()
for next_p in G[p]:
if visit[next_p-1] == -1:
visit[next_p-1] = visit[p-1] + 1
q.append(next_p)
for l in range(N):
d[visit[l]] += 1
for k in range(1, N):
print((d[k]//2))
|
N, X, Y = list(map(int, input().split()))
d = [0] * N
for i in range(0, N-1):
for j in range(i+1, N):
k = min(j-i, abs(X-1-i) + 1 + abs(Y-1-j))
d[k] += 1
for i in range(1, N):
print((d[i]))
|
p02726
|
import queue
N,X,Y=list(map(int,input().split()))
X -= 1
Y -= 1
INF = 1001001001
ans=[0]*N
def push(v, d):
if dist[v]!= INF:
return
dist[v]=d
q.put(v)
for sv in range(N):
q=queue.Queue()
dist=[INF]*N
push(sv,0)
while(not q.empty()):
v=q.get()
d=dist[v]
if v-1 >= 0:
push(v-1, d+1)
if v+1 < N:
push(v+1,d+1)
if v==X:
push(Y,d+1)
if v==Y:
push(X,d+1)
for i in range(N):
ans[dist[i]] +=1
for i in range(1,N):
print((int(ans[i]/2)))
|
import queue
N,X,Y=list(map(int,input().split()))
X-=1
Y-=1
ans=[0]*N
for i in range(N-1):
for j in range(i+1,N):
ans[min(j-i, abs(X-i)+1+abs(Y-j))]+=1
for i in range(1,N):
print((ans[i]))
|
p02726
|
import queue
N,X,Y=list(map(int,input().split()))
count=[0]*N
def bfs(start):
dist=[-1]*(N+1)#indexと頂点の番号を合わせる
q=queue.Queue()
q.put([start,0])
dist[start]=0
while not q.empty():
j,kyori=q.get()
if j-1>=1:
if dist[j-1]==-1:
q.put([j-1,kyori+1])
dist[j-1]=kyori+1
if j+1<=N:
if dist[j+1]==-1:
q.put([j+1,kyori+1])
dist[j+1]=kyori+1
if j == X and dist[Y]==-1:
q.put([Y,kyori+1])
dist[Y]=kyori+1
if j == Y and dist[X]==-1:
q.put([X,kyori+1])
dist[X]=kyori+1
return dist[1:]
def main():
for start in range(1,N+1):
#dist=bfs(start)
for d in bfs(start):
count[d]+=1
for i in count[1:]:
print((i//2))
main()
|
from collections import deque
N,X,Y=list(map(int,input().split()))
count=[0]*N
def bfs(start):
dist=[-1]*(N+1)#indexと頂点の番号を合わせる
q=deque()
q.append([start,0])
dist[start]=0
while q:
j,kyori=q.popleft()
if j-1>=1:
if dist[j-1]==-1:
q.append([j-1,kyori+1])
dist[j-1]=kyori+1
if j+1<=N:
if dist[j+1]==-1:
q.append([j+1,kyori+1])
dist[j+1]=kyori+1
if j == X and dist[Y]==-1:
q.append([Y,kyori+1])
dist[Y]=kyori+1
if j == Y and dist[X]==-1:
q.append([X,kyori+1])
dist[X]=kyori+1
return dist[1:]
def main():
for start in range(1,N+1):
dist=bfs(start)
for d in dist:
count[d]+=1
for i in count[1:]:
print((i//2))
main()
|
p02726
|
from collections import Counter, deque, defaultdict
n, x, y = list(map(int, input().split()))
v = defaultdict(list)
for i in range(n):
if i + 1 < n: v[i].append(i + 1)
if i - 1 >= 0: v[i].append(i - 1)
v[x - 1].append(y - 1)
v[y - 1].append(x - 1)
cnt = Counter()
for start in range(n):
dist = [float("inf")] * n
q = deque()
q.append([start, 0])
while q:
c, d = q.popleft()
for next in v[c]:
if dist[next] == float("inf"):
q.append([next, d + 1])
dist[next] = d + 1
cnt += Counter(dist[start + 1:])
for i in range(1, n):
print((cnt[i]))
|
from collections import Counter, deque, defaultdict
def main():
n, x, y = list(map(int, input().split()))
v = defaultdict(list)
for i in range(n):
if i + 1 < n: v[i].append(i + 1)
if i - 1 >= 0: v[i].append(i - 1)
v[x - 1].append(y - 1)
v[y - 1].append(x - 1)
cnt = Counter()
for start in range(n):
dist = [-1] * n
q = deque()
q.append([start, 0])
while q:
c, d = q.popleft()
for next in v[c]:
if dist[next] == -1:
q.append([next, d + 1])
dist[next] = d + 1
cnt += Counter(dist[start + 1:])
for i in range(1, n):
print((cnt[i]))
if __name__ == '__main__':
main()
|
p02726
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
d= [[float('inf')]*n for _ in range(n)]
for i in range(n-1):
if i == 0:
d[0][1] = 1
d[n-1][n-2] = 1
else:
d[i][i+1] = 1
d[i][i-1] = 1
for i in range(n):
d[i][i] = 0
d[x][y] = 1
d[y][x] = 1
def warshall_floyd(d):
#d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
d = warshall_floyd(d)
from collections import defaultdict
di = defaultdict(int)
for i in range(n):
for j in range(i+1, n):
di[d[i][j]] += 1
for i in range(1, n):
if i in list(di.keys()):
print((di[i]))
else:
print((0))
|
from collections import deque
from collections import defaultdict
n, x, y = list(map(int, input().split()))
graph = [[] for _ in range(n)]
for i in range(n-1):
graph[i] += [i+1]
graph[i+1] += [i]
graph[x-1] += [y-1]
graph[y-1] += [x-1]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))
def bfs(s):
dist = [float('inf')]*n
dist[s] = 0
q = deque([s])
while q:
u = q.popleft()
for v in graph[u]:
if dist[v] == float('inf'):
q += [v]
dist[v] = dist[u] + 1
return dist
ans = defaultdict(int)
for i in range(n):
d = bfs(i)
for j in range(i+1, n):
ans[d[j]] += 1
for i in range(1, n):
if i in list(ans.keys()):
print((ans[i]))
else:
print((0))
|
p02726
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
edge = []
for i in range(N):
edge.append([])
if i != 0:
edge[i].append(i - 1)
if i != N-1:
edge[i].append(i + 1)
edge[X].append(Y)
edge[Y].append(X)
answer = [0] * (N - 1)
for i in range(N):
queue = []
for e in edge[i]:
queue.append(e)
counter = 0
d = [N + 10] * N
d[i] = 0
# i is start
while counter < len(queue):
node = queue[counter]
min_dist = N + 10
for e in edge[node]:
min_dist = min(d[e], min_dist)
d[node] = min_dist + 1
for e in edge[node]:
if d[e] == N+10:
queue.append(e)
counter += 1
for i in d:
answer[i] += 1
for a in answer[1:]:
print((a//2))
print('0')
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
edge = []
for i in range(N):
edge.append([])
if i != 0:
edge[i].append(i - 1)
if i != N-1:
edge[i].append(i + 1)
edge[X].append(Y)
edge[Y].append(X)
answer = [0] * (N - 1)
for i in range(N):
queue = []
for e in edge[i]:
queue.append(e)
counter = 0
d = [N + 10] * N
d[i] = 0
# i is start
while counter < len(queue):
node = queue[counter]
min_dist = N + 10
for e in edge[node]:
if d[e] < min_dist:
min_dist = d[e]
if d[e] == N + 10:
queue.append(e)
d[node] = min_dist + 1
counter += 1
for i in d:
answer[i] += 1
for a in answer[1:]:
print((a//2))
print('0')
|
p02726
|
import queue
N, X, Y = list(map(int, input().split()))
to = [[] * N for i in range(N)]
for i in range(N-1):
to[i].append(i+1)
to[i+1].append(i)
to[X-1].append(Y-1)
to[Y-1].append(X-1)
ans = [0] * N
for i in range(N):
dis = [0] * N
dis[i] = 0
visited = [False] * N
q = queue.Queue()
q.put(i)
visited[i] = True
while not q.empty():
tmp_v = q.get()
for j in to[tmp_v]:
if not visited[j]:
dis[j] = dis[tmp_v] + 1
visited[j] = True
q.put(j)
for j in range(N):
ans[dis[j]] += 1
for i in range(1,N):
print((ans[i]//2))
|
from collections import deque
N, X, Y = list(map(int, input().split()))
to = [[] * N for i in range(N)]
for i in range(N-1):
to[i].append(i+1)
to[i+1].append(i)
to[X-1].append(Y-1)
to[Y-1].append(X-1)
ans = [0] * N
for i in range(N):
dis = [0] * N
dis[i] = 0
visited = [False] * N
q = deque([])
q.append(i)
visited[i] = True
while len(q) != 0:
tmp_v = q.popleft()
for j in to[tmp_v]:
if not visited[j]:
dis[j] = dis[tmp_v] + 1
visited[j] = True
q.append(j)
for j in range(N):
ans[dis[j]] += 1
for i in range(1,N):
print((ans[i]//2))
|
p02726
|
from collections import deque
N,X,Y = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N):
if i == 0:
edge[i].append(i+1)
elif i == N-1:
edge[i].append(i-1)
else:
edge[i].append(i-1)
edge[i].append(i+1)
edge[X-1].append(Y-1)
edge[Y-1].append(X-1)
ans = [0]*(N-1)
for i in range(N):
visited = [0]*N
dist = [0]*N
q = deque([i])#i番目のノードを根とする探索
visited[i] = 1
while q:
now = q.popleft()
for connection in edge[now]:
if visited[connection]:
dist[connection] = min(dist[connection],dist[now]+1)
else:
visited[connection] = 1
dist[connection] = dist[now] + 1
q.append(connection)
for d in dist:
if d == 0:
continue
ans[d-1] += 1
ans = list(map(lambda x: x//2,ans))
print(*ans,sep="\n")
|
from collections import deque
import sys
input = sys.stdin.readline
def main():
N,X,Y = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N):
if i == 0:
edge[i].append(i+1)
elif i == N-1:
edge[i].append(i-1)
else:
edge[i].append(i-1)
edge[i].append(i+1)
edge[X-1].append(Y-1)
edge[Y-1].append(X-1)
ans = [0]*(N-1)
for i in range(N):
visited = [0]*N
dist = [0]*N
q = deque([i])#i番目のノードを根とする探索
visited[i] = 1
while q:
now = q.popleft()
for connection in edge[now]:
if visited[connection]:
dist[connection] = min(dist[connection],dist[now]+1)
else:
visited[connection] = 1
dist[connection] = dist[now] + 1
q.append(connection)
for d in dist:
if d == 0:
continue
ans[d-1] += 1
ans = list(map(lambda x: x//2,ans))
print(*ans,sep="\n")
if __name__ == '__main__':
main()
|
p02726
|
N,X,Y=list(map(int,input().split()))
G=[]
for i in range(1,N):
G.append([i,i+1])
G.append([X,Y])
graph=[[] for i in range(N+1)]
for i in range(N):
u,*v=G[i]
v.sort()
for j in v:
graph[u].append(j)
graph[j].append(u)
counter=[[] for i in range(N+1)]
for j in range(1,N+1):
stack=[j]
visited=[-1 for i in range(N+1)]
visited[j]=0
while stack:
n=stack.pop(0)
for i in graph[n]:
n_n=i
if visited[n_n]<0:
visited[n_n]=visited[n]+1
stack.append(n_n)
for i,value in enumerate(visited):
for k in range(1,N):
if value==k:
counter[k].append([j,i])
for i,value in enumerate(counter):
if not (i==0 or i==N):
print((int(len(value)/2)))
|
N,X,Y=list(map(int,input().split()))
A=[[] for i in range(N+1)]
for i in range(1,N):
for j in range(i,N+1):
A[int(min(j-i,abs(X-i)+abs(Y-j)+1))].append(1)
for i in range(N):
if i!=0:
print((sum(A[i])))
|
p02726
|
N,X,Y=list(map(int,input().split()))
A=[[] for i in range(N+1)]
for i in range(1,N):
for j in range(i,N+1):
A[int(min(j-i,abs(X-i)+abs(Y-j)+1))].append(1)
for i in range(N):
if i!=0:
print((sum(A[i])))
|
N,X,Y=list(map(int,input().split()))
A=[0 for i in range(N)]
for i in range(1,N):
for j in range(i+1,N+1):
A[int(min(j-i,abs(X-i)+abs(Y-j)+1))]+=1
del A[0]
print(*A,sep=('\n'))
|
p02726
|
n,x,y = list(map(int,input().split()))
a = [0 for _ in range(n-1)]
for i in range(1,n):
for j in range(i+1,n+1):
l = min(j-i,abs(x-i)+1+abs(j-y))
a[l-1] += 1
print(("\n".join(map(str,a))))
|
def main():
n,x,y = list(map(int,input().split()))
a = [0 for _ in range(n-1)]
for i in range(1,n):
for j in range(i+1,n+1):
l = min(j-i,abs(x-i)+1+abs(j-y))
a[l-1] += 1
print(("\n".join(map(str,a))))
main()
|
p02726
|
from collections import defaultdict
n, x, y = list(map(int, input().split()))
d = defaultdict(int)
for i in range(1, n):
for j in range(i + 1, n + 1):
a = j - i
b = abs(x - i) + 1 + abs(y - j)
d[min(a, b)] += 1
for i in range(1, n):
print((d[i]))
|
from collections import defaultdict
n, x, y = list(map(int, input().split()))
d = defaultdict(int)
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)] += 1
for i in range(1, n):
print((d[i]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
for k in range(1,N):
d = 0
for i in range(1,N+1):
for j in range(i+1,N+1):
if k==min(j-i, abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X)):
d+=1
print(d)
|
N, X, Y = list(map(int, input().split()))
a = [0]*N
for i in range(1,N+1):
for j in range(i+1,N+1):
a[min(j-i, abs(i-X)+1+abs(j-Y))-1]+= 1
for i in range(N-1):
print((a[i]))
|
p02726
|
n,x,y=map(int,input().split())
G=[[i,i+2] for i in range(n)]
G[0],G[-1]=[2],[n-1]
G[x-1].append(y)
G[y-1].append(x)
#print(G)
ans=[0]*(n-1)
#X,Yのショートカットに気を付けて上から見ていく
for i in range(n-1):
for j in range(i+1,n):
#i+1<=XかつY<=j+1の時ショートカットするのが最短
temp1=j-i
temp2=abs(x-(i+1))+1+abs(y-(j+1))
dis=min(temp1,temp2)
ans[dis-1]+=1
print(*ans,sep='\n')
|
n,x,y=map(int,input().split())
G=[[i,i+2] for i in range(n)]
G[0],G[-1]=[2],[n-1]
G[x-1].append(y)
G[y-1].append(x)
#print(G)
ans=[0]*(n-1)
for i in range(n-1):
for j in range(i+1,n):
temp1=j-i
temp2=abs(x-(i+1))+1+abs(y-(j+1))
dis=min(temp1,temp2)
ans[dis-1]+=1
print(*ans,sep='\n')
|
p02726
|
n, x, y = map(int,input().split())
dis = [0] * (n - 1)
for i in range(n - 1):
for j in range(i + 1, n):
d = min(abs(x - i - 1) + abs(y - j - 1) + 1, j - i)
dis[d - 1] += 1
print(*dis, sep = '\n')
|
n, x, y = map(int,input().split())
cnt = [0] * (n - 1)
for i in range(1, n):
for j in range(i + 1, n + 1):
temp1 = j - i
temp2 = abs(i - x) + abs(j - y) + 1
dis = min(temp1, temp2)
cnt[dis - 1] += 1
print(*cnt, sep='\n')
|
p02726
|
N, X, Y = list(map(int, input().split()))
List = []
for i in range(1,N):
for j in range(i+1, N+1):
List.append(min(j-i, abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X)))
for k in range(1, N):
print((List.count(k)))
|
N, X, Y = list(map(int, input().split()))
List = [0 for _ in range(N-1)]
for i in range(1,N):
for j in range(i+1, N+1):
num = min(j-i, abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X))
List[num-1] += 1
for k in range(N-1):
print((List[k]))
|
p02726
|
import itertools
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
list1 = [0] * (n * n)
for i in range(n):
for j in range(n):
if list1[n * j + i] != 0:
continue
list1[n * i + j] = min([abs(j - i), abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(x - j)])
#list2 = list(itertools.chain.from_iterable(list1))
for k in range(1,n):
print((list1.count(k)))
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
cnt_list = [0] * (n - 1)
for i in range(n):
for j in range(n):
if j <= i:
continue
#i < j,x < yのとき、i→y→x→jが最短になることはない
num = min([j - i, abs(x - i) + 1 + abs(y - j)]) - 1 #距離 - 1、距離ゼロはif文で排除
cnt_list[num] += 1
for n in cnt_list:
print(n)
|
p02726
|
import itertools
N,X,Y = list(map(int,input().split()))
n = list(range(1,N+1))
l = []
for v in itertools.combinations(n,2):
l.append(min(abs(Y-v[1]) + abs(X-v[0]) + 1,abs(X-v[1]) + abs(Y-v[0]) + 1,v[1] - v[0]))
for k in range(1,N):
print((l.count(k)))
|
import itertools
N,X,Y = list(map(int,input().split()))
n = list(range(1,N+1))
l = [0]*N
for v in itertools.combinations(n,2):
l[min(abs(Y-v[1]) + abs(X-v[0]) + 1,v[1] - v[0])] += 1
for k in range(1,N):
print((l[k]))
|
p02726
|
from collections import Counter
import queue
def bfs(d, s, N):
dist = [-1]*N
q = queue.Queue()
q.put(s)
dist[i] = 0
while not q.empty():
From = q.get()
for To in d[From]:
if dist[To-1] == -1:
q.put(To)
dist[To-1] = dist[From-1]+1
return dist
N, X, Y = list(map(int, input().split()))
d = [[] for _ in range(N+1)]
d[X].append(Y)
d[Y].append(X)
for i in range(1, N):
d[i].append(i+1)
d[i+1].append(i)
ans = [0]*(N+1)
for i in range(N):
s = i+1
c = Counter(bfs(d, i+1, N))
for i, m in list(c.items()):
ans[i] += m
for i in range(1, N):
print((ans[i]//2))
|
from collections import Counter, deque
def bfs(d, s, N):
dist = [-1]*N
q = deque()
q.append(s)
dist[i] = 0
while len(q) != 0:
From = q.popleft()
for To in d[From]:
if dist[To-1] == -1:
q.append(To)
dist[To-1] = dist[From-1]+1
return dist
N, X, Y = list(map(int, input().split()))
d = [[] for _ in range(N+1)]
d[X].append(Y)
d[Y].append(X)
for i in range(1, N):
d[i].append(i+1)
d[i+1].append(i)
ans = [0]*(N+1)
for i in range(N):
s = i+1
c = Counter(bfs(d, i+1, N))
for i, m in list(c.items()):
ans[i] += m
for i in range(1, N):
print((ans[i]//2))
|
p02726
|
n, x, y = list(map(int, input().split()))
distances = []
for ind1 in range(1,n+1):
for ind2 in range(ind1+1,n+1):
cur_dist = min(ind2-ind1, abs(x-ind1)+abs(y-ind2)+1)
# print(ind1,ind2,cur_dist)
distances.append(cur_dist)
# print(distances)
for k in range(1,n):
print((len([x for x in distances if x == k])))
|
n, x, y = list(map(int, input().split()))
cnt = [0] *n
for ind1 in range(1,n+1):
for ind2 in range(ind1+1,n+1):
cur_dist = min(ind2-ind1, abs(x-ind1)+abs(y-ind2)+1)
# print(ind1,ind2,cur_dist)
cnt[cur_dist] += 1
# print(cnt)
for k in range(1,n):
print((cnt[k]))
|
p02726
|
import itertools
n,x,y = list(map(int, input().split()))
a = [i for i in range(1, n+1)]
b = list(itertools.combinations(a, 2))
c = [0]*(n-1)
for j in range(len(b)):
d = min(abs(b[j][0]-b[j][1]), abs(x-b[j][0])+1+abs(b[j][1]-y), abs(y-b[j][0])+1+abs(b[j][1]-x))
c[d-1] += 1
for k in range(n-1):
print((c[k]))
|
import itertools
n,x,y = list(map(int, input().split()))
a = [i for i in range(1, n+1)]
b = [0]*(n-1)
for j in range(n):
for k in range(j+1, n):
c = min(abs(k-j),abs(j-(x-1)) +abs(k-(y-1))+1)
b[c-1] += 1
for l in range(n-1):
print((b[l]))
|
p02726
|
#!/usr/bin/env python3
import sys
def solve(N: int, X: int, Y: int):
distances = [0] * (N - 1)
for i in range(0, N - 1):
for j in range(i + 1, N):
if j < X - 1 or Y - 1 < i:
distance = j - i
else:
distance = min(j - i, abs(X - 1 - i) + abs(Y - 1 - j) + 1)
distances[distance - 1] += 1
for k in distances:
print(k)
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
solve(N, X, Y)
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
import sys
def solve(N: int, X: int, Y: int):
distances = [0] * (N - 1)
for i in range(0, N - 1):
for j in range(i + 1, N):
distance = min(j - i, abs(X - 1 - i) + abs(Y - 1 - j) + 1)
distances[distance - 1] += 1
for k in distances:
print(k)
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
solve(N, X, Y)
if __name__ == '__main__':
main()
|
p02726
|
import sys
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
d = [[sys.maxsize for _ in range(N)] for _ in range(N)]
for i in range(N):
for j in range(N):
d[i][j] = min(abs(j-i), abs(X-i) + 1 + abs(j-Y))
answer = [0 for _ in range(N-1)]
for h in range(N):
for i in range(h+1, N):
if h != i:
answer[d[h][i]-1] += 1
for k in range(N-1):
print((answer[k]))
|
import sys
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
answer = [0 for _ in range(N-1)]
for i in range(N):
for j in range(i+1, N):
answer[min(j-i, abs(X-i) + 1 + abs(j-Y))-1] += 1
for k in range(N-1):
print((answer[k]))
|
p02726
|
from collections import defaultdict
n,x,y=list(map(int,input().split()))
d=defaultdict(list)
for i in range(1,n):
for j in range(i+1,n+1):
r=min(abs(i-j),abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))
d[r].append((i,j))
for i in range(1,n):
print((len(d[i])))
|
n,x,y=list(map(int,input().split()))
l=[0]*(n-1)
for i in range(1,n):
for j in range(i+1,n+1):
l[(min(abs(i-j),abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i)))-1]+=1
for i in l:
print(i)
|
p02726
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
distances = [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+abs(j-X))
distances[d] += 1
for i in range(1,N):
print((distances[i]))
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
distances = [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+abs(j-X))
d = min(abs(j-i), abs(X-i)+1+abs(j-Y))
distances[d] += 1
for i in range(1,N):
print((distances[i]))
|
p02726
|
from collections import defaultdict
import math
N, X, Y = list(map(int, input().split()))
res = defaultdict(int)
x = []
for i in range(1, N + 1):
for j in range(1, N + 1):
if i >= j:
continue
if i == X and Y == j:
key = 1
else:
key = int(min(j - i, math.fabs(X - i) + math.fabs(Y - j) + 1))
res[key] += 1
for i in range(1, N):
print((res[i]))
|
N, X, Y = list(map(int, input().split()))
res = [0] * N
for i in range(1, N + 1):
for j in range(1, N + 1):
if i >= j:
continue
if i == X and Y == j:
key = 1
else:
key = int(min(j - i, abs(X - i) + abs(Y - j) + 1))
res[key] += 1
for i in range(1, N):
print((res[i]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
res = [0] * N
for j in range(1, N + 1):
for i in range(1, j):
if i == X and Y == j:
key = 1
else:
key = int(min(j - i, abs(X - i) + abs(Y - j) + 1))
res[key] += 1
for i in range(1, N):
print((res[i]))
|
N, X, Y = list(map(int, input().split()))
res = [0] * N
for j in range(1, N + 1):
for i in range(1, j):
res[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1
for i in range(1, N):
print((res[i]))
|
p02726
|
from collections import defaultdict
import math
N, X, Y = list(map(int, input().split()))
res = defaultdict(int)
x = []
for i in range(1, N + 1):
for j in range(1, N + 1):
if i >= j:
continue
if i == X and Y == j:
key = 1
else:
key = int(min(j - i, math.fabs(X - i) + math.fabs(Y - j) + 1))
res[key] += 1
for i in range(1, N):
print((res[i]))
|
N, X, Y = list(map(int, input().split()))
res = [0] * N
for j in range(1, N + 1):
for i in range(1, j):
res[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1
for i in range(1, N):
print((res[i]))
|
p02726
|
n,x,y=map(int,input().split())
x-=1;y-=1
l=[[10**4 for g in range(n)] for i in range(n)]
fl=[0 for i in range(n-1)]
for i in range(n):
for j in range(i+1,n):
fl[min(abs(j-i),abs(j-x)+1+abs(y-i),abs(i-x)+1+abs(y-j))]+=1
print(*fl[1:],sep="\n")
print(fl[0])
|
n,x,y=map(int,input().split())
x-=1;y-=1
fl=[0 for i in range(n-1)]
for i in range(n):
for j in range(i+1,n):
fl[min(abs(j-i),abs(j-x)+1+abs(y-i),abs(i-x)+1+abs(y-j))]+=1
print(*fl[1:],sep="\n")
print(0)
|
p02726
|
n,x,y = list(map(int,input().split()))
INF = 10**5
d = [[INF]*n for _ in range(n)]
def wf(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])
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
wf(d)
ans = [0]*(n-1)
for i in range(n-1):
for j in range(i+1,n):
ans[d[i][j]-1]+=1
for a in ans:
print(a)
|
n,x,y = list(map(int,input().split()))
x,y = x-1,y-1
ans = [0]*(n)
for i in range(n):
for j in range(i+1,n):
sp = min(abs(j-i), abs(x-i)+abs(j-y)+1, abs(y-i)+1+abs(j-x))
ans[sp]+=1
for a in ans[1:]:
print(a)
|
p02726
|
N,X,Y = list(map(int,input().split()))
G = [[] for _ in range(N)]
# print(G)
# ぐらふの作成
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)
# print(G)
from collections import deque
def bfs(G,v):
que = deque([v])
dist[v] = 0
while que:
v = que.popleft()
d = dist[v]
for w in G[v]:
if dist[w] > -1:
continue
dist[w] = d + 1
que.append(w)
D = [0]*(N-1)
for i in range(N):
dist = [-1]*N
bfs(G,i)
# print(dist)
for d in dist:
if d>0:
D[d-1] += 1
# print(D)
for d in D:
print((d//2))
|
N,X,Y = list(map(int,input().split()))
D= [0]*(N-1)
# print(X,Y)
for i in range(1,N+1):
for j in range(i+1,N+1): # i<j
# print((i,j))
# ver 1
if j<=X or Y<=i:
d = j-i
# ver 2
elif i<=X and Y<=j:
d = X-i + 1 + j-Y
# ver 3
else:
d = min(j-i,abs(X-i)+abs(Y-j)+1)
# print(d)
D[d-1] += 1
# print(D)
for d in D:
print(d)
|
p02726
|
N,X,Y = list(map(int,input().split()))
D= [0]*(N-1)
# print(X,Y)
for i in range(1,N+1):
for j in range(i+1,N+1): # i<j
# print((i,j))
# ver 1
if j<=X or Y<=i:
d = j-i
# ver 2
elif i<=X and Y<=j:
d = X-i + 1 + j-Y
# ver 3
else:
d = min(j-i,abs(X-i)+abs(Y-j)+1)
# print(d)
D[d-1] += 1
# print(D)
for d in D:
print(d)
|
N,X,Y = list(map(int,input().split()))
D= [0]*(N-1)
for i in range(1,N+1):
for j in range(i+1,N+1): # i<j
d = min(j-i,abs(X-i)+abs(Y-j)+1)
D[d-1] += 1
for d in D:
print(d)
|
p02726
|
from collections import deque
n,x,y=list(map(int,input().split()))
L=[[0]*n for i in range(n)]
for i in range(n-1):
L[i][i+1]=L[i+1][i]=1
L[x-1][y-1]=L[y-1][x-1]=1
R=[0]*n
def bfs(j):
V=[-1]*n
que=deque([])
que.append(j)
V[j]=0
while que:
p=que.popleft()
for i in range(n):
if V[i]==-1 and L[p][i]==1:
que.append(i)
V[i]=V[p]+1
for i in range(n):
R[V[i]]+=1
for j in range(n):
bfs(j)
for i in range(1,n):
print((R[i]//2))
|
from collections import deque
n,x,y=list(map(int,input().split()))
L=[[1]]
for i in range(1,n-1):
L.append([i-1,i+1])
L.append([n-2])
L[x-1].append(y-1)
L[y-1].append(x-1)
R=[0]*n
def bfs(j):
V=[-1]*n
que=deque([])
que.append(j)
V[j]=0
while que:
p=que.popleft()
for np in L[p]:
if V[np]==-1:
que.append(np)
V[np]=V[p]+1
for i in range(n):
R[V[i]]+=1
for j in range(n):
bfs(j)
for i in range(1,n):
print((R[i]//2))
|
p02726
|
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
if b:
print("yes")
else:
print("no")
def Yn(b):
if b:
print("Yes")
else:
print("No")
def YN(b):
if b:
print("YES")
else:
print("NO")
class union_find():
def __init__(self,n):
self.n=n
self.P=[a for a in range(n)]
self.rank=[0]*n
def find(self,x):
if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
return self.P[x]
def same(self,x,y):
return self.find(x)==self.find(y)
def link(self,x,y):
if self.rank[x]<self.rank[y]:
self.P[x]=y
elif self.rank[y]<self.rank[x]:
self.P[y]=x
else:
self.P[x]=y
self.rank[y]+=1
def unite(self,x,y):
self.link(self.find(x),self.find(y))
def size(self):
S=set()
for a in range(self.n):
S.add(self.find(a))
return len(S)
def ispow(a,b):#aはbの累乗数か
now=b
while now<a:
now*=b
if now==a:return True
else:return False
def getbin(num,size):
A=[0]*size
for a in range(size):
if (num>>(size-a-1))&1==1:
A[a]=1
else:
A[a]=0
return A
def getfacs(n,mod_=0):
A=[1]*(n+1)
for a in range(2,len(A)):
A[a]=A[a-1]*a
if(mod_>0):A[a]%=mod_
return A
def comb(n,r,mod,fac):
if(n-r<0):return 0
return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
x=num&(-num)
y=num+x
z=num&(~y)
z//=x
z=z>>1
num=(y|z)
if(num>=(1<<size)):return False
else:return num
def getprimes(n,type="int"):
if n==0:
if type=="int":return []
else:return [False]
A=[True]*(n+1)
A[0]=False
A[1]=False
for a in range(2,n+1):
if A[a]:
for b in range(a*2,n+1,a):
A[b]=False
if(type=="bool"):return A
B=[]
for a in range(n+1):
if(A[a]):B.append(a)
return B
def isprime(num):
if(num<=1):return False
i=2
while i*i<=num:
if(num%i==0):return False
i+=1
return True
def ifelse(a,b,c):
if a:return b
else:return c
def join(A,c=""):
n=len(A)
A=list(map(str,A))
s=""
for a in range(n):
s+=A[a]
if(a<n-1):s+=c
return s
def factorize(n,type_="dict"):
b = 2
list_ = []
while b * b <= n:
while n % b == 0:
n //= b
list_.append(b)
b+=1
if n > 1:list_.append(n)
if type_=="dict":
dic={}
for a in list_:
if a in dic:
dic[a]+=1
else:
dic[a]=1
return dic
elif type_=="list":
return list_
else:
return None
def pm(x):
return x//abs(x)
def inputintlist():
return list(map(int,input().split()))
######################################################################################################
N,X,Y=inputintlist()
X-=1
Y-=1
G=[[] for a in range(N)]
for a in range(N-1):
G[a].append(a+1)
G[a+1].append(a)
G[X].append(Y)
G[Y].append(X)
A=[]
for a in range(N):
for b in range(a,N):
d=b-a
d=min(d,abs(a-X)+1+abs(b-Y))
d=min(d,abs(a-Y)+1+abs(b-X))
A.append(d)
for k in range(1,N):
print((A.count(k)))
|
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
if b:
print("yes")
else:
print("no")
def Yn(b):
if b:
print("Yes")
else:
print("No")
def YN(b):
if b:
print("YES")
else:
print("NO")
class union_find():
def __init__(self,n):
self.n=n
self.P=[a for a in range(n)]
self.rank=[0]*n
def find(self,x):
if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
return self.P[x]
def same(self,x,y):
return self.find(x)==self.find(y)
def link(self,x,y):
if self.rank[x]<self.rank[y]:
self.P[x]=y
elif self.rank[y]<self.rank[x]:
self.P[y]=x
else:
self.P[x]=y
self.rank[y]+=1
def unite(self,x,y):
self.link(self.find(x),self.find(y))
def size(self):
S=set()
for a in range(self.n):
S.add(self.find(a))
return len(S)
def ispow(a,b):#aはbの累乗数か
now=b
while now<a:
now*=b
if now==a:return True
else:return False
def getbin(num,size):
A=[0]*size
for a in range(size):
if (num>>(size-a-1))&1==1:
A[a]=1
else:
A[a]=0
return A
def getfacs(n,mod_=0):
A=[1]*(n+1)
for a in range(2,len(A)):
A[a]=A[a-1]*a
if(mod_>0):A[a]%=mod_
return A
def comb(n,r,mod,fac):
if(n-r<0):return 0
return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
x=num&(-num)
y=num+x
z=num&(~y)
z//=x
z=z>>1
num=(y|z)
if(num>=(1<<size)):return False
else:return num
def getprimes(n,type="int"):
if n==0:
if type=="int":return []
else:return [False]
A=[True]*(n+1)
A[0]=False
A[1]=False
for a in range(2,n+1):
if A[a]:
for b in range(a*2,n+1,a):
A[b]=False
if(type=="bool"):return A
B=[]
for a in range(n+1):
if(A[a]):B.append(a)
return B
def isprime(num):
if(num<=1):return False
i=2
while i*i<=num:
if(num%i==0):return False
i+=1
return True
def ifelse(a,b,c):
if a:return b
else:return c
def join(A,c=""):
n=len(A)
A=list(map(str,A))
s=""
for a in range(n):
s+=A[a]
if(a<n-1):s+=c
return s
def factorize(n,type_="dict"):
b = 2
list_ = []
while b * b <= n:
while n % b == 0:
n //= b
list_.append(b)
b+=1
if n > 1:list_.append(n)
if type_=="dict":
dic={}
for a in list_:
if a in dic:
dic[a]+=1
else:
dic[a]=1
return dic
elif type_=="list":
return list_
else:
return None
def pm(x):
return x//abs(x)
def inputintlist():
return list(map(int,input().split()))
######################################################################################################
N,X,Y=inputintlist()
X-=1
Y-=1
G=[[] for a in range(N)]
for a in range(N-1):
G[a].append(a+1)
G[a+1].append(a)
G[X].append(Y)
G[Y].append(X)
D=defaultdict(int)
for a in range(N):
for b in range(a,N):
d=b-a
d=min(d,abs(a-X)+1+abs(b-Y))
d=min(d,abs(a-Y)+1+abs(b-X))
D[d]+=1
for k in range(1,N):
print((D[k]))
|
p02726
|
from collections import deque
def BFS(s):
color=["white" for _ in range(n+1)]
D=[0 for _ in range(n+1)]
D[s]=0
color[s]="gray"
queue=deque([s])
while len(queue)>0:
u=queue.popleft()
for i in M[u]:
if color[i]=="white":
D[i]=D[u]+1
color[i]="gray"
queue.append(i)
color[u]="black"
return D
n,x,y=list(map(int,input().split()))
M=[[] for _ in range(n+1)]
for i in range(1,n):
M[i].append(i+1)
M[i+1].append(i)
M[x].append(y)
M[y].append(x)
A=[0]*(n)
for i in range(1,n+1):
for j in BFS(i)[i:]:
A[j] +=1
for i in A[1:]:
print(i)
|
from collections import deque
inf=10**9
def BFS(num):
color=["white" for _ in range(n+1)]
D=[inf for _ in range(n+1)]
queue=deque([num])
color[num]="gray"
D[num]=0
while len(queue)>0:
u=queue.popleft()
for i in M[u]:
if color[i]=="white" and D[u]+1<D[i]:
D[i]=D[u]+1
color[i]="gray"
queue.append(i)
color[u]="black"
return D
n,x,y=list(map(int,input().split()))
M=[[] for _ in range(n+1)]
for i in range(1,n):
M[i].append(i+1)
M[i+1].append(i)
M[x].append(y)
M[y].append(x)
ans=[0 for _ in range(n-1)]
for i in range(1,n+1):
for j in BFS(i)[i+1:]:
ans[j-1] +=1
for i in ans:
print(i)
|
p02726
|
from collections import deque
def main():
n, x, y = list(map(int, input().split()))
cnt = [0]*n
q = deque()
for i in range(n):
q.appendleft([i, 0])
dist = [None]*n
dist[i] = 0
while q:
j, d = q.pop()
cnt[d] += 1
if j > 0 and dist[j-1] is None:
dist[j-1] = d+1
q.appendleft([j-1, d+1])
if j < n-1 and dist[j+1] is None:
dist[j+1] = d+1
q.appendleft([j+1, d+1])
if j == x-1 and dist[y-1] is None:
dist[y-1] = d+1
q.appendleft([y-1, d+1])
elif j == y-1 and dist[x-1] is None:
dist[x-1] = d+1
q.appendleft([x-1, d+1])
for i in range(1, n):
print((cnt[i]//2))
if __name__ == "__main__":
main()
|
from collections import deque
def main():
n, x, y = list(map(int, input().split()))
cnt = [0]*n
q = deque()
for i in range(n):
q.appendleft(i)
dist = [None]*n
dist[i] = 0
while q:
j = q.pop()
d = dist[j]
cnt[d] += 1
if j > 0 and dist[j-1] is None:
dist[j-1] = d+1
q.appendleft(j-1)
if j < n-1 and dist[j+1] is None:
dist[j+1] = d+1
q.appendleft(j+1)
if j == x-1 and dist[y-1] is None:
dist[y-1] = d+1
q.appendleft(y-1)
elif j == y-1 and dist[x-1] is None:
dist[x-1] = d+1
q.appendleft(x-1)
for i in range(1, n):
print((cnt[i]//2))
if __name__ == "__main__":
main()
|
p02726
|
import queue
def push(n, dist, dist_list):
if dist_list[n] > dist:
dist_list[n] = dist
q.put(n)
q = queue.Queue()
n, x, y = [int(i) for i in input().split()]
result = [0] * (n-1)
for p in range(n):
dist_list = [111111] * n
dist = 0
q.put(p)
dist_list[p] = dist
while not q.empty():
p = q.get()
dist = dist_list[p]
if p+1 < n: push(p+1, dist+1, dist_list)
if p-1 >= 0: push(p-1, dist+1, dist_list)
if p == (x-1): push(y-1, dist+1, dist_list)
if p == (y-1): push(x-1, dist+1, dist_list)
for i in dist_list:
if i != 0:
result[i-1] += 1
for ans in result:
print((ans//2))
|
n, x, y = [int(i) for i in input().split()]
# 0 index is 1 distance
result = [0] * (n-1)
for i in range(n-1):
for j in range(i+1, n):
dist = min(j-i, abs(x-1-i) + 1 + abs(j-y+1))
result[dist-1] += 1
for ans in result:
print(ans)
# TLE
# import queue
# q = queue.Queue()
# n, x, y = [int(i) for i in input().split()]
# result = [0] * (n-1)
# for p in range(n):
# dist_list = [111111] * n
# dist = 0
# q.put(p)
# dist_list[p] = dist
# while not q.empty():
# p = q.get()
# dist = dist_list[p]
# if p+1 < n:
# if dist_list[p+1] > dist:
# dist_list[p+1] = dist
# q.put(p+1)
# if p-1 < n:
# if dist_list[p-1] > dist:
# dist_list[p-1] = dist
# q.put(p-1)
# if p == (x-1):
# if dist_list[y-1] > dist:
# dist_list[y-1] = dist
# q.put(y-1)
# if p == (y-1):
# if dist_list[x-1] > dist:
# dist_list[x-1] = dist
# q.put(x-1)
# for i in dist_list:
# if i != 0:
# result[i-1] += 1
# for ans in result:
# print(ans//2)
|
p02726
|
def s0():return eval(input())
def s1():return input().split()
def s2(n):return [eval(input()) for x in range(n)]
def n0():return int(eval(input()))
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(eval(input())) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
n,x,y=n1()
a=[]
for i in range(1,n+1):
for j in range(i+1,n+1):
if i<=x and j<=x:
a.append([(i,j),j-i])
elif i<=x and x<j<y:
a.append([(i,j),min(j-i,y-j+1+x-i)])
elif i<=x:
a.append([(i,j),j-y+1+x-i])
elif i<=y and j<=y:
a.append([(i,j),min(j-i,y-j+1+i-x)])
elif i<=y:
a.append([(i,j),min(j-i,j-y+1+i-x)])
else:
a.append([(i,j),j-i])
for k in range(1,n):
ans=0
for h in range(len(a)):
if a[h][1]==k:
ans+=1
print(ans)
|
def s0():return eval(input())
def s1():return input().split()
def s2(n):return [eval(input()) for x in range(n)]
def n0():return int(eval(input()))
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(eval(input())) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
n,x,y=n1()
a=[0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
if i<=x and j<=x:
a[j-i]+=1
elif i<=x and x<j<y:
a[min(j-i,y-j+1+x-i)]+=1
elif i<=x:
a[j-y+1+x-i]+=1
elif i<=y and j<=y:
a[min(j-i,y-j+1+i-x)]+=1
elif i<=y:
a[min(j-i,j-y+1+i-x)]+=1
else:
a[j-i]+=1
for k in range(1,n):
print((a[k]))
|
p02726
|
import sys
from collections import deque
def main():
# n, x, y = 7, 3, 7
n, x, y = [int(s) for s in sys.stdin.readline().strip().split()]
score = {i: 0 for i in range(1, n)}
total_pair = set()
def bfs(start):
seen = set()
q = deque()
q.append((0, start))
while q:
dist, cur = q.popleft()
pair = (min(start, cur), max(start, cur))
if pair in seen:
continue
seen.add(pair)
if dist > 0:
if pair not in total_pair:
score[dist] += 1
total_pair.add(pair)
if cur < n-1:
q.append((dist+1, cur+1))
if cur > 0:
q.append((dist+1, cur-1))
if cur == x-1:
q.append((dist+1, y-1))
if cur == y-1:
q.append((dist+1, x-1))
for i in range(n-1):
bfs(i)
for i in range(1, n):
print((score[i]))
main()
|
import sys
def main():
n, x, y = [int(s) for s in sys.stdin.readline().strip().split()]
x1 = x-1
y1 = y-1
score = {i:0 for i in range(n)}
for i in range(n-1):
for j in range(i+1, n):
diff = j - i
cand = abs(x1 - i) + 1 + abs(y1 - j)
cand2 = abs(y1 - i) + 1 + abs(x1 - j)
result = min(diff, cand, cand2)
score[result] += 1
for i in range(1, n):
print((score[i]))
main()
|
p02726
|
N, X, Y = [int(i) for i in input().split()]
gp = [[float('inf')]*N for _ in range(N)]
def warshall_floyd(d,n):
#d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
for i in range(N-1):
gp[i][i+1] = 1
gp[i+1][i] = 1
if(i==X-1):
gp[i][Y-1] = 1
gp[Y-1][i] = 1
d = warshall_floyd(gp, N)
li = [0]*(N-1)
for i in range(N):
for j in range(i+1, N):
li[d[i][j]-1] += 1
for i in li:
print(i)
|
N, X, Y = [int(i) for i in input().split()]
li = [0]*(N-1)
for i in range(1, N+1):
for j in range(i+1, N+1):
k = 0
if(i<X and j<X):
k = j-i
if(i<X and X<=j<=Y):
k = min(j-i, X-i+1+Y-j)
if(i<X and Y<j):
k = X-i+1+j-Y
if(X<=i<=Y and X<=j<=Y):
k = min(j-i, i-X+1+Y-j)
if(X<=i<=Y and Y<j):
k = min(j-i, i-X+1+j-Y)
if(Y<i and Y<j):
k = j-i
li[k-1] += 1
for i in li:
print(i)
|
p02726
|
n, a1, a2 = list(map(int, input().split(" ")))
anscount = [0 for i in range(n + 1)]
for i in range(1, n):
for j in range(i + 1, n + 1):
anscount[min(abs(j - i), abs(i - a1) + abs(j - a2) + 1, abs(i - a2) + abs(j - a1) + 1)] += 1
for i in range(1, n):
print((anscount[i]))
|
n, a1, a2 = list(map(int, input().split(" ")))
print(n)
wa = a2 - a1 + 1
l1 = a1 - 1
l2 = n - a2
hwa = wa // 2
pari = wa % 2
# print(wa,l1,l2,hwa,pari)
tmp = 0
for i in range(2, n):
if l1 + l2 + 1 >= i:
tmp += l1 + l2 - i + 2
if i - 1 <= l1:
tmp -= 1
if i - 1 <= l2:
tmp -= 1
# print("himonokazu",tmp)
if hwa > i:
tmp += wa
elif hwa == i:
if pari == 1:
tmp += wa
else:
tmp += hwa
# print("wamoirete",tmp)
# print((i-1),(hwa-1),(l1-1),l2-1)
if i <= hwa + l1:
# print(min(hwa,l1,hwa+l1-i+1,i-1))
tmp += min(hwa, l1, hwa + l1 - i + 1, i - 1) * 2
if pari == 0 and hwa < i:
tmp -= 1
# print("l1gen")
# print("l1",tmp)
if i <= hwa + l2:
# print(min(hwa,l2,hwa+l2-i+1,i-1))
tmp += min(hwa, l2, hwa + l2 - i + 1, i - 1) * 2
if pari == 0 and hwa < i:
tmp -= 1
# print("l2gen")
# print("l2", tmp)
print(tmp)
tmp = 0
|
p02726
|
N,X,Y=list(map(int,input().split()))
def count(k):
ans=0
for i in range(1,N):
for j in range(i+1,N+1):
if min(abs(j-i),abs(X-i)+abs(Y-j)+1)==k:
ans+=1
return ans
for k in range(1,N):
print((count(k)))
|
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(abs(j-i),abs(X-i)+abs(Y-j)+1)]+=1
for i in range(1,N):
print((ans[i]))
|
p02726
|
n, x, y = list(map(int, input().split()))
edge = [[] for _ in range(n+1)]
dist = [[abs(i-j) for i in range(n+1)] for j in range(n+1)]
counter = [0 for i in range(n)]
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(y+1):
for j in range(x, n+1):
new_dist = abs(x-i)+abs(y-j)+1
if new_dist < dist[i][j]:
dist[i][j] = new_dist
dist[j][i] = new_dist
for i in range(1, n+1):
for num in dist[i][1:]:
counter[num] += 1
# print(dist)
for num in counter[1:]:
print((num//2))
|
n, x, y = list(map(int, input().split()))
edge = [[] for _ in range(n+1)]
dist = [[abs(i-j) for i in range(n+1)] for j in range(n+1)]
counter = [0 for i in range(n)]
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(y+1):
for j in range(x, n+1):
if j > i:
new_dist = abs(x-i)+abs(y-j)+1
if new_dist < dist[i][j]:
dist[i][j] = new_dist
for i in range(1, n+1):
for num in dist[i][i+1:]:
counter[num] += 1
# print(dist)
for num in counter[1:]:
print(num)
|
p02726
|
N, X, Y = list(map(int, input().split()))
ans = [0] * N
X -= 1
Y -= 1
for i in range(N):
for j in range(i+1, N):
distance = abs(i-j)
# X Y i j
if Y <= i:
pass
# i j X Y
elif j <= X:
pass
# X i Y j
elif X <= i < Y <= j:
dis = (i-X) + 1 + (j-Y)
distance = min(distance, dis)
# i X j Y
elif i <= X < j <= Y:
dis = (X-i) + 1 + (Y-j)
distance = min(distance, dis)
# i X Y j
elif i <= X < Y <= j:
dis = (X-i) + 1 + (j-Y)
distance = min(distance, dis)
# X i j Y
elif X <= i < j <= Y:
dis = (i-X) + 1 + (Y-j)
distance = min(distance, dis)
ans[distance] += 1
for k in range(1, N):
print((ans[k]))
|
N, X, Y = list(map(int, input().split()))
ans = [0] * N
X -= 1
Y -= 1
for i in range(N):
for j in range(i+1, N):
distance = min(abs(i-j), abs(i-X) + 1 + abs(j-Y))
ans[distance] += 1
for k in range(1, N):
print((ans[k]))
|
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):
if i <= X and j <= X:
dic = j-i
elif i >= Y and j >= Y:
dic = j-i
elif i <= X and j >= Y:
dic = (j-i)-(Y-X)+1
elif X < i < Y and j >= Y:
dic = min(i-X+1,Y-i)+(j-Y)
elif i<=X and X < j < Y:
dic = (X-i)+min(Y-j+1,j-X)
elif X < i < Y and X < j < Y:
dic = min(j-i,(i-X+1)+(Y-j))
ans[dic-1] = ans[dic-1]+1
for ret in ans:
print(ret)
|
n,x,y = list(map(int,input().split()))
ans = [0]*(n-1)
def f(N,X,Y):
for i in range(1,N):
for j in range(i+1,N+1):
if i <= X and j <= X:
dic = j-i
elif i >= Y and j >= Y:
dic = j-i
elif i <= X and j >= Y:
dic = (j-i)-(Y-X)+1
elif X < i < Y and j >= Y:
dic = min(i-X+1,Y-i)+(j-Y)
elif i<=X and X < j < Y:
dic = (X-i)+min(Y-j+1,j-X)
elif X < i < Y and X < j < Y:
dic = min(j-i,(i-X+1)+(Y-j))
ans[dic-1] = ans[dic-1]+1
f(n,x,y)
for ret in ans:
print(ret)
|
p02726
|
n, x, y = list(map(int, input().split()))
kyori = []
def clc(i1, i2):
return min(1 + abs(i2 - y) + abs(i1 - x), i2 - i1)
for k in range(1, n+1):
for l in range(k+1, n+1):
tmp = clc(k, l)
kyori.append(tmp)
for i in range(n-1):
cnt = 0
for k in kyori:
if k == i + 1:
cnt += 1
print(cnt)
|
n, x, y = list(map(int, input().split()))
kyori = []
def clc(i1, i2):
if (i1 < x and i2 <= x) or (y <= i1 and y < i2):
return i2 - i1
else:
return min(1 + abs(i2 - y) + abs(i1 - x), i2 - i1)
for k in range(1, n+1):
for l in range(k+1, n+1):
tmp = clc(k, l)
kyori.append(tmp)
outs = [0 for _ in range(n-1)]
for k in kyori:
outs[k-1] += 1
for i in range(n-1):
print((outs[i]))
|
p02726
|
from itertools import *
n,x,y=map(int,input().split())
a=[0]*n
for i,j in combinations(range(1,n+1),2):
b=min(abs(i-j),abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))
a[b]+=1
print(*a[1:],sep="\n")
|
n,x,y=map(int,input().split())
a=[0]*n
for i in range(1,n+1):
for j in range(i,n+1):
b=min(abs(i-j),abs(i-x)+1+abs(y-j),abs(x-j)+1+abs(y-i))
a[b]+=1
print(*a[1:],sep="\n")
|
p02726
|
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())
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=LI()
cost = [[inf for i in range(n)] for i in range(n)]
for i in range(n-1):
cost[i][i+1]=1
cost[i+1][i]=1
cost[x-1][y-1]=1
cost[y-1][x-1]=1
ans=[0]*(n-1)
for i in range(n):
a=dijkstra(i,n,n,cost)
for x in a[i:]:
ans[x]+=1
for x in ans[1:]:
print(x)
print((0))
main()
# print(main())
|
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())
def dijkstra_heap(s,edge):
#始点sから各頂点への最短距離
d = [10**20] * n
used = [True] * n #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for a,b in edge[s]:
heapq.heappush(edgelist,a*(10**6)+b)
while len(edgelist):
minedge = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge%(10**6)]:
continue
v = minedge%(10**6)
d[v] = minedge//(10**6)
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
return d
n,x,y=LI()
edge = [[] for i in range(n)]
for i in range(n-1):
edge[i].append([1,i+1])
edge[i+1].append([1,i])
edge[x-1].append([1,y-1])
edge[y-1].append([1,x-1])
ans=[0]*n
for i in range(n):
a=dijkstra_heap(i,edge)
# print(a)
for x in a[i:]:
ans[x]+=1
for x in ans[1:]:
print(x)
|
p02726
|
from heapq import heappush, heappop
def solve(N, X, Y):
ans = [0] * (N)
G = [[] for _ in range(N + 1)]
for i in range(1, N):
G[i].append(i + 1)
G[i + 1].append(i)
G[X].append(Y)
G[Y].append(X)
def dfs(vertex):
nears = [float('inf')] * (N + 1)
depth = 0
que = [[depth, vertex]]
while que:
d, v = heappop(que)
if d < nears[v]:
nears[v] = d
for g in G[v]:
heappush(que, [d + 1, g])
return nears
for i in range(1, N):
# dfs
nears = dfs(i)
# print(nears)
for j in range(i + 1, N + 1):
ans[nears[j]] += 1
for i in ans[1:]:
print(i)
if __name__ == '__main__':
N, X, Y = list(map(int, input().split()))
solve(N, X, Y)
|
# 解説を参考に作成
def solve(N, X, Y):
ans = [0] * (N)
for i in range(1, N):
for j in range(i + 1, N + 1):
k = min(abs(j - i), abs(X - i) + 1 + abs(Y - j))
ans[k] += 1
for i in ans[1:]:
print(i)
if __name__ == '__main__':
N, X, Y = list(map(int, input().split()))
solve(N, X, Y)
|
p02726
|
mod = 10**9 + 7
def iip(listed = False):
ret = [int(i) for i in input().split()]
if len(ret) == 1 and not listed:
return ret[0]
return ret
def soinsuu_bunkai(n):
ret = []
for i in range(2, int(n**0.5)+1):
while n % i == 0:
n //= i
ret.append(i)
if i > n:
break
if n != 1:
ret.append(n)
return ret
def conbination(n, r, mod, test=False):
if n <=0:
return 0
if r == 0:
return 1
if r < 0:
return 0
if r == 1:
return n
ret = 1
for i in range(n-r+1, n+1):
ret *= i
ret = ret % mod
bunbo = 1
for i in range(1, r+1):
bunbo *= i
bunbo = bunbo % mod
ret = (ret * inv(bunbo, mod)) % mod
if test:
#print(f"{n}C{r} = {ret}")
pass
return ret
def inv(n, mod):
return power(n, mod-2)
def power(n, p):
if p == 0:
return 1
if p % 2 == 0:
return (power(n, p//2) ** 2) % mod
if p % 2 == 1:
return (n * power(n, p-1)) % mod
#####################################################ライブラリ集ここまで
def main():
N, X, Y = iip()
X -= 1
Y -= 1
ret = 0
result = []
for k in range(1, N):
ret = 0
for i in range(N):
ret += search(i, k, N, X, Y)
result.append(str(ret))
print(("\n".join(result)))
def search(a, k, N, X, Y):
kouho = []
if abs(a-X)+1+abs(a+k-Y) >= k and abs(a-Y) + 1 + abs(a+k-X) >= k:
#print(f"追加 {a+k} a, k = {a}, {k} by 条件1")
kouho.append(a+k)
asy = k-abs(a-X)-1
if asy < 0:
pass
elif asy == 0:
if abs(a-X) + 1 <= abs(a-Y):
kouho.append(Y)
#print(f"追加 {Y} a, k = {a}, {k} by 条件6")
else:
if abs(a-(Y-asy)) > k:
kouho.append(Y-asy)
#print(f"追加 {Y-asy} a, k = {a}, {k} by 条件2")
if abs(a-(Y+asy)) > k:
#print(f"追加 {Y+asy} a, k = {a}, {k} by 条件3")
kouho.append(Y+asy)
asx = k-abs(a-Y)-1
if asx < 0:
pass
elif asx == 0:
if abs(a-Y) + 1 < abs(a-X):
kouho.append(X)
#print(f"追加 {X} a, k = {a}, {k} by 条件7")
else:
if abs(a-(X-asx)) > k:
kouho.append(X-asx)
#print(f"追加 {X-asx} a, k = {a}, {k} by 条件4")
if abs(a-(X+asx)) > k:
kouho.append(X+asx)
#print(f"追加 {X+asx} a, k = {a}, {k} by 条件5")
kakutei = []
result = 0
for kh in kouho:
if kh == a:
continue
if kh < 0:
continue
if kh > N-1:
continue
if kh in kakutei:
continue
if kh < a:
continue
kakutei.append(kh)
result += 1
#print(f"--result開始 a, k = {a}, {k}")
#print(result)
#print(kakutei)
#print("--result終了")
return result
if __name__ == "__main__":
main()
|
mod = 10**9 + 7
def iip(listed = False):
ret = [int(i) for i in input().split()]
if len(ret) == 1 and not listed:
return ret[0]
return ret
def soinsuu_bunkai(n):
ret = []
for i in range(2, int(n**0.5)+1):
while n % i == 0:
n //= i
ret.append(i)
if i > n:
break
if n != 1:
ret.append(n)
return ret
def conbination(n, r, mod, test=False):
if n <=0:
return 0
if r == 0:
return 1
if r < 0:
return 0
if r == 1:
return n
ret = 1
for i in range(n-r+1, n+1):
ret *= i
ret = ret % mod
bunbo = 1
for i in range(1, r+1):
bunbo *= i
bunbo = bunbo % mod
ret = (ret * inv(bunbo, mod)) % mod
if test:
#print(f"{n}C{r} = {ret}")
pass
return ret
def inv(n, mod):
return power(n, mod-2)
def power(n, p):
if p == 0:
return 1
if p % 2 == 0:
return (power(n, p//2) ** 2) % mod
if p % 2 == 1:
return (n * power(n, p-1)) % mod
#####################################################ライブラリ集ここまで
def main():
N, X, Y = iip()
X, Y = sorted((X-1, Y-1))
#print(X, Y)
result = [0 for i in range(1, N)]
for a in range(0, N):
for b in range(a+1, N):
d1 = b-a
d2 = abs(X-a)+abs(Y-b)+1
d = min(d1, d2)-1
#print(a, b, d)
result[d] += 1
print(("\n".join([str(i) for i in result])))
if __name__ == "__main__":
main()
|
p02726
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
import heapq
from collections import defaultdict
INF = float("inf")
class Graph(object):
def __init__(self, N):
self.N = N
self.E = defaultdict(list)
def add_edge(self, s, t, w=1):
self.E[s].append((t, w))
self.E[t].append((s, w))
def shortestPath(g: Graph, s: int):
# 返り値 (dist, prev)
# dist: 始点からの距離が格納されたリスト
# prev: 始点から最短経路で移動する場合、各頂点に至る前の頂点のリスト
dist = [INF]*g.N
dist[s] = 0
prev = [None]*g.N
Q = []
heapq.heappush(Q, (dist[s], s))
while len(Q) > 0:
_, u = heapq.heappop(Q)
for v, w in g.E[u]:
if dist[v] > dist[u] + w:
dist[v] = dist[u] + w
prev[v] = u
heapq.heappush(Q, (dist[v], v))
return dist, prev
def solve(N: int, X: int, Y: int):
g = Graph(N)
for i in range(1, N):
g.add_edge(i-1, i)
g.add_edge(X-1, Y-1)
ans = [0]*N
for i in range(N):
dist, prev = shortestPath(g, i)
for j, d in enumerate(dist):
if i < j:
ans[d] += 1
print(*ans[1:], sep="\n")
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
solve(N, X, Y)
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
import heapq
from collections import defaultdict
INF = float("inf")
def solve(N: int, X: int, Y: int):
if X > Y:
X, Y = Y, X
ans = [0]*N
for i in range(N):
for j in range(i+1, N):
d = min(abs(j-i), abs(i-(X-1))+1+abs(j-(Y-1)))
ans[d] += 1
print(*ans[1:], sep="\n")
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
solve(N, X, Y)
if __name__ == '__main__':
main()
|
p02726
|
from collections import deque
n,x,y=list(map(int,input().split()))
g = [[i-1,i+1] for i in range(1,n-1)]
g.insert(0,[1])
g.append([n-2])
g[x-1].append(y-1)
g[y-1].append(x-1)
dist = []
def bfs(i):
d = [float("inf")]*n
que = deque([])
que.append(i)
d[i] = 0
while que:
idx = que.popleft()
l = g[idx]
for j in l:
if d[j] == float("inf"):
d[j] = d[idx] + 1
que.append(j)
elif d[j] > d[idx] + 1:
d[j] = d[idx] + 1
que.append(j)
dist.extend(d)
for i in range(n):
bfs(i)
dist.sort()
for i in range(1,n):
print((dist.count(i)//2))
|
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):
a = min(j-i, abs(x-i)+1+abs(y-j))
ans[a-1] += 1
for i in range(n-1):
print((ans[i]))
|
p02726
|
import bisect as bs
n,x,y = list(map(int,input().split()))
x -= 1
y -= 1
array = [[-1 for i in range(n)] for j in range(n)]
for i in range(n):
for j in range(n):
array[i][j] = abs(j-i)
for i in range(n):
if array[i][x] == array[i][y]:
pass
elif array[i][x] > array[i][y]:
array[i][x] = array[i][y] + 1
index = x - 1
while True:
if index < 0 or array[i][index] <= array[i][index+1]:
break
array[i][index] = array[i][index+1] + 1
index -= 1
index = x + 1
while True:
if index >= n or array[i][index] <= array[i][index-1]:
break
array[i][index] = array[i][index-1] + 1
index += 1
else:
array[i][y] = array[i][x] + 1
index = y - 1
while True:
if index < 0 or array[i][index] <= array[i][index+1]:
break
array[i][index] = array[i][index+1] + 1
index -= 1
index = y + 1
while True:
if index >= n or array[i][index] <= array[i][index-1]:
break
array[i][index] = array[i][index-1] + 1
index += 1
ans = [0] * (n+1)
for i in range(n):
for j in range(i, n):
tmp = array[i][j]
ans[tmp] += 1
for i in range(1,n):
print((ans[i]))
|
n,x,y = list(map(int,input().split()))
x -= 1
y -= 1
array1 = [0] * n
array2 = [0] * n
for i in range(x, y+1):
array1[i] = min(i-x, y-i+1)
array2[i] = min(i-x+1, y-i)
ans = [0] * (n+1)
dis = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
if i <= x:
for j in range(i+1,n):
if y <= j:
tmp = (x-i) + (j-y) + 1
elif j <= x:
tmp = j-i
else:
tmp = (x-i) + array1[j]
ans[tmp] += 1
dis[i][j] = tmp
elif y <= i:
for j in range(i+1,n):
ans[j-i] += 1
dis[i][j] = j-i
else:
for j in range(i+1,n):
if y <= j:
tmp = (j-y) + array2[i]
else:
tmp = min(j-i, (y-x+1)-(j-i))
ans[tmp] += 1
dis[i][j] = tmp
for i in range(1,n):
print((ans[i]))
|
p02726
|
n, x, y = list(map(int, input().split()))
def distance(i,j):
d1 = abs(i-j)
d2 = abs(i-x)+1+abs(j-y)
d3 = abs(i-y)+1+abs(j-x)
d = min(d1,d2,d3)
return d
d = [0]*(n-1)
for i in range(1, n+1):
for j in range(i+1,n+1):
d[distance(i,j)-1] = d[distance(i,j)-1] + 1
for i in d:
print(i)
|
n, x, y = list(map(int, input().split()))
d = [0]*(n-1)
for i in range(1, n+1):
for j in range(i+1,n+1):
c = min(j-i, abs(i-x)+1+abs(j-y))
d[c-1] = d[c-1] + 1
for i in d:
print(i)
|
p02726
|
from collections import deque, Counter
def bfs(start, graph):
q = deque([(start, 0)])
visited = set()
while q:
curr, dist = q.popleft()
if curr not in visited:
yield start, curr, dist
visited.add(curr)
for neighbor in graph[curr]:
q.append((neighbor, dist + 1))
if __name__ == '__main__':
n, x, y = tuple([int(i) for i in input().split()])
graph = {i: [] for i in range(1, n + 1)}
for i in range(1, n):
graph[i].append(i + 1)
graph[i + 1].append(i)
graph[min(x, y)].append(max(x, y))
graph[max(x, y)].append(min(x, y))
dists = [0 for k in range(n)]
distances = {}
for i in range(1, n):
for s, e, d in bfs(i, graph):
if s != e:
start = min(s, e)
end = max(s, e)
key = (start, end)
if key in list(distances.keys()):
distances[key] = min(distances[key], d)
else:
distances[key] = d
dists = Counter(list(distances.values()))
for k in range(1, n):
print((dists[k] if k in list(dists.keys()) else 0))
|
def distance(i, j, x, y):
return min([abs(j - i), abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x)])
if __name__ == '__main__':
n, x, y = tuple([int(i) for i in input().split()])
x, y = min(x, y), max(x, y)
dists = [0 for k in range(n)]
for i in range(1, n):
for j in range(i + 1, n + 1):
d = distance(i, j, x, y)
dists[d] += 1
for k in dists[1:]:
print(k)
|
p02726
|
from collections import deque
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
# nl = lambda: list(map(int, input().split()))
n,x,y=nm()
class Node:
def __init__(self,x):
self.val = x
self.left=[]
self.right=[]
nodes = [Node(i) for i in range(n)]
for i in range(n-1):
nodes[i].right.append(nodes[i+1])
nodes[i+1].left.append(nodes[i])
nodes[x-1].right.append(nodes[y-1])
nodes[y-1].left.append(nodes[x-1])
gl_dist = [0]*n
for i in range(n):
dist = [-1]*n
dist[i]=0
q = deque()
q.append(nodes[i])
while len(q) > 0:
node = q.popleft()
nv = node.val
nl = node.left
nr = node.right
for nli in nl:
if dist[nli.val] == -1:
dist[nli.val] = dist[nv]+1
q.append(nli)
for nri in nr:
if dist[nri.val] == -1:
dist[nri.val] = dist[nv]+1
q.append(nri)
for j in range(i+1,n):
# print("{} to {} is {}".format(i,j,dist[j]))
if dist[j] != -1:
gl_dist[dist[j]]+=1
for i in range(1,n):
print((gl_dist[i]))
# print(gl_dist)
|
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
n,x,y = nm()
dist = [0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
naive = j-i
cand = naive
if i<x:
if x<=j<=y:
cand = x-i+1+y-j
elif j>y:
cand = x-i+1+j-y
elif x<=i<=y:
if j<=y:
cand = i-x+1+y-j
else:
cand = i-x+1+j-y
d = min(naive,cand)
dist[d]+=1
for i in range(1,n):
print((dist[i]))
|
p02726
|
import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, X, Y = list(map(int, readline().split()))
X -= 1
Y -= 1
G = [[] for _ in range(N)]
for i in range(N - 1):
G[i].append(i + 1)
G[i + 1].append(i)
G[X].append(Y)
G[Y].append(X)
count = [0] * N
for i in range(N):
dist = [-1] * N
dist[i] = 0
queue = deque([i])
while queue:
v = queue.popleft()
for nv in G[v]:
if dist[nv] == -1:
dist[nv] = dist[v] + 1
count[dist[nv]] += 1
queue.append(nv)
ans = [c // 2 for c in count[1:]]
print(('\n'.join(map(str, ans))))
return
if __name__ == '__main__':
main()
|
import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, X, Y = list(map(int, readline().split()))
X -= 1
Y -= 1
ans = [0] * N
for i in range(N - 1):
for j in range(i + 1, N):
d = min(j - i, abs(i - X) + 1 + abs(Y - j), abs(j - X) + 1 + abs(X - i))
ans[d] += 1
print(('\n'.join(map(str, ans[1:]))))
return
if __name__ == '__main__':
main()
|
p02726
|
from collections import deque
def main():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
ans = [0 for _ in range(N)]
for s in range(N):
dist = [-1 for _ in range(N)]
dist[s] = 0
d = deque([s])
while(len(d) > 0):
v = d.popleft()
if v == X:
if dist[Y] == -1:
d.append(Y)
dist[Y] = dist[v] + 1
if v == Y:
if dist[X] == -1:
d.append(X)
dist[X] = dist[v] + 1
if v + 1 < N:
if dist[v+1] == -1:
d.append(v+1)
dist[v+1] = dist[v] + 1
if v - 1 >= 0:
if dist[v-1] == -1:
d.append(v-1)
dist[v-1] = dist[v] + 1
for i in range(N):
ans[dist[i]] += 1
for k in range(1, N):
print((ans[k] // 2))
if __name__ == "__main__":
main()
|
from collections import deque
def main():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
ans = [0 for _ in range(N)]
for s in range(N):
dist = [-1 for _ in range(N)]
dist[s] = 0
d = deque([s])
while(len(d) > 0):
v = d.popleft()
if v == X:
if dist[Y] == -1:
d.append(Y)
dist[Y] = dist[v] + 1
elif v == Y:
if dist[X] == -1:
d.append(X)
dist[X] = dist[v] + 1
if v + 1 < N:
if dist[v+1] == -1:
d.append(v+1)
dist[v+1] = dist[v] + 1
if v - 1 >= 0:
if dist[v-1] == -1:
d.append(v-1)
dist[v-1] = dist[v] + 1
for i in range(N):
ans[dist[i]] += 1
for k in range(1, N):
print((ans[k] // 2))
if __name__ == "__main__":
main()
|
p02726
|
n, x, y = list(map(int, input().split()))
li = [0]*(n-1)
num = 0
for i in range(1,n+1):
for j in range(i+1,n+1):
if j<=x or y<i:
num = j-i
elif i<=x and x<j<=y:
num = (x-i)+min(j-x, y-j+1)
elif i<=x and y<j:
num = (x-i)+(j-y)+1
elif x<i and j<=y:
num = min(j-i,(i-x)+(y-j)+1)
elif x<i<=y and y<j:
num = min(i-x+1, y-i)+(j-y)
li[num-1] += 1
for i in li:
print(i)
|
n, x, y = list(map(int, input().split()))
li = [0] * (n - 1)
num = 0
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
num = min(j-i, abs(i-x)+abs(j-y)+1)
li[num - 1] += 1
for i in li:
print(i)
|
p02726
|
from collections import deque
n,x,y=list(map(int,input().split()))
t=deque()
for i in range(1,n+1):
for j in range(i+1,n+1):
t.append(min(abs(j-i),abs(i-x)+abs(j-y)+1))
for k in range(1,n):
print((t.count(k)))
|
n,x,y=map(int,input().split())
t=[0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
t[min(abs(j-i),abs(i-x)+abs(j-y)+1)]+=1
print(*t[1:],sep='\n')
|
p02726
|
n,x,y = list(map(int,input().split()))
ans = {}
for i in range(1,n):
for j in range(i+1,n+1):
dist = min(abs(i-j),abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
if dist in list(ans.keys()):
ans[dist] += 1
else:
ans[dist] = 1
for k in range(1,n):
if k in list(ans.keys()):
print((ans[k]))
else:
print((0))
|
n,x,y = list(map(int,input().split()))
ans = {}
s = (y-x+1)//2
s = x+s
for i in range(1,n):
for j in range(i+1,n+1):
if i <= s:
dist = min(j-i,abs(i-x)+abs(j-y)+1)
else:
dist = j-i
if dist in list(ans.keys()):
ans[dist] += 1
else:
ans[dist] = 1
for k in range(1,n):
if k in list(ans.keys()):
print((ans[k]))
else:
print((0))
|
p02726
|
#D
line = [int(x) for x in input().split()]
n = line[0]
x = line[1]
y = line[2]
results =[0]*(n+2)
for i in range(1, n):
for j in range(i+1,n+1):
yeet = min([abs(j-i), abs(x-i) + 1 + abs(j-y), abs(y-i) + 1 + abs(j-x)])
results[yeet-1] += 1
for i in range(0, n-1):
print((results[i]))
|
#D
line = [int(x) for x in input().split()]
n = line[0]
x = line[1]
y = line[2]
results =[0]*(n+2)
for i in range(1, n):
for j in range(i+1,n+1):
results[min([abs(j-i), abs(x-i) + 1 + abs(j-y)])-1] += 1
for i in range(0, n-1):
print((results[i]))
|
p02726
|
n,x,y=list(map(int,input().split()))
ans=[0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
a1=abs(i-j)
a2=abs(x-i)+1+abs(y-j)
a3=abs(y-i)+1+abs(x-j)
d=min(a1,a2,a3)
ans[d]+=1
for i in range(1,n):
print((ans[i]))
|
n,x,y=list(map(int,input().split()))
ans=[0]*n #個数を数えるのにバケットを用意する
for i in range(1,n+1): #i<jなるすべての頂点の組について最短距離を求める
for j in range(i+1,n+1):
dist1=j-i
dist2=abs(x-i)+abs(y-j)+1
dist3=abs(y-i)+abs(x-j)+1
d=min(dist1,dist2,dist3) #最短距離は上式により求められる
ans[d]+=1 #最短距離がdとなる組の個数を1増やす
for i in range(1,n):
print((ans[i]))
|
p02726
|
n,x,y=list(map(int,input().split()))
ans=[0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
a1=abs(i-j)
a2=abs(x-i)+1+abs(y-j)
a3=abs(y-i)+1+abs(x-j)
d=min(a1,a2,a3)
ans[d]+=1
for i in range(1,n):
print((ans[i]))
|
n,x,y=list(map(int,input().split()))
ans=[0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
a1=j-i
a2=abs(x-i)+1+abs(y-j)
a3=abs(y-i)+1+abs(x-j)
d=min(a1,a2,a3)
ans[d]+=1
for i in range(1,n):
print((ans[i]))
|
p02726
|
#!/usr/bin/env python3
from collections import deque
n, x, y = list(map(int, input().split()))
to = [[] for _ in range(n)]
for i in range(n):
if i == 0:
to[i].append(i+1)
elif i == n-1:
to[i].append(i-1)
else:
to[i].append(i+1)
to[n-i-1].append(n-i-2)
to[x-1].append(y-1)
to[y-1].append(x-1)
anss = [0 for _ in range(n-1)]
# 頂点'start'からBFS
def bfs(start):
inf = 1001001001
dist = [inf for _ in range(n)]
q = deque()
q.append(start)
dist[start] = 0
while q:
v = q.popleft()
for u in to[v]:
if dist[u] == inf:
dist[u] = dist[v]+1
q.append(u)
# print('start = ', start, ': dist = ', dist)
for k in range(1, n):
cnt = 0
for i in range(n):
if cnt > 3:
break
if dist[i]-dist[start] == k:
anss[k-1] += 1
cnt += 1
for i in range(n):
bfs(i)
for i in range(n-1):
print((anss[i]//2))
|
#!/usr/bin/env python3
# TLE解
from collections import deque
n, x, y = list(map(int, input().split()))
to = [[] for _ in range(n)]
for i in range(n):
if i == 0:
to[i].append(i+1)
elif i == n-1:
to[i].append(i-1)
else:
to[i].append(i+1)
to[n-i-1].append(n-i-2)
to[x-1].append(y-1)
to[y-1].append(x-1)
ans = [0 for _ in range(n)]
# 頂点'start'からBFS
def bfs(start):
inf = 1001001001
dist = [inf for _ in range(n)]
q = deque()
q.append(start)
dist[start] = 0
while q:
v = q.popleft()
for u in to[v]:
if dist[u] == inf:
dist[u] = dist[v]+1
q.append(u)
# print('start = ', start, ': dist = ', dist)
# for k in range(1, n):
# for i in range(n):
# if dist[i]-dist[start] == k:
# ans[k-1] += 1
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
|
import math
import bisect
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
b=[]
for i in range(1,50):
b.append(2**i)
ct=0
check=[1]*n
for i in range(n-1,-1,-1):
if a[i]==1:
break
if check[i]==1 and a[i] not in b:
check[i]=0
x=math.floor(math.log2(a[i]))
x=b[x]-a[i]
y=bisect.bisect_left(a,x)
z=bisect.bisect_right(a,x)
t=bisect.bisect_left(check[y:z],1)+y
if t!=z:
check[t]=0
ct+=1
ctb=0
w=1
for i in range(n):
if a[i] in b or a[i]==1:
if a[i]==w:
if check[i]==1:
ctb+=1
else:
ct+=ctb//2
w=a[i]
if check[i]==1:
ctb=1
else:
ctb=0
else:
ct+=ctb//2
ctb=0
ct+=ctb//2
print(ct)
|
import math
import bisect
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
x=a[0]
ctn=1
l=[]
l2=[]
for i in range(1,n):
if x==a[i]:
ctn+=1
else:
l.append([x,ctn])
l2.append(x)
x=a[i]
ctn=1
l.append([x,ctn])
l2.append(x)
b=[]
for i in range(1,50):
b.append(2**i)
ct=0
for i in range(len(l2)-1,-1,-1):
x=math.floor(math.log2(l2[i]))
x=b[x]-l2[i]
y=bisect.bisect_left(l2,x)
if l2[y]==x:
if l2[y]!=l2[i]:
m=min(l[i][1],l[y][1])
else:
m=l[i][1]//2
l[i][1]-=m
l[y][1]-=m
ct+=m
print(ct)
|
p03201
|
import math
from collections import defaultdict
def main():
_ = int(eval(input()))
nums = list(map(int, input().split()))
n = len(nums)
nums.sort()
nums_cnt = defaultdict(int)
for num in nums:
nums_cnt[num] += 1
cnt = 0
#print(num_bin_digits)
for cur in reversed(list(range(n))):
num = nums[cur]
if nums_cnt[num] <= 0:
continue
power_of_2 = 1 << math.ceil(math.log2(num))
pair = power_of_2 - num
if pair != 0 and nums_cnt[pair] > 0:
nums_cnt[pair] -= 1
nums_cnt[num] -= 1
cnt += 1
elif pair == 0 and nums_cnt[num] >= 2:
nums_cnt[num] -= 2
cnt += 1
'''
idx = bisect.bisect_left(nums, pair)
if idx >= cur or nums[idx] != pair:
#print('continue',pair, idx)
continue
while used[idx]:
idx += 1
if nums[idx] == pair:
used[idx] = True
cnt += 1
#print(idx, num, power_of_2, pair)
#print(cnt, nums, used)
'''
#print(nums_cnt)
print(cnt)
return
main()
|
import math
from collections import defaultdict
def main():
n = int(eval(input()))
nums = list(map(int, input().split()))
nums.sort()
nums_cnt = defaultdict(int)
for num in nums:
nums_cnt[num] += 1
cnt = 0
for num in reversed(nums):
if nums_cnt[num] <= 0:
continue
power_of_2 = 1 << math.ceil(math.log2(num))
pair = power_of_2 - num
if pair != 0 and nums_cnt[pair] > 0:
nums_cnt[pair] -= 1
nums_cnt[num] -= 1
cnt += 1
elif pair == 0 and nums_cnt[num] >= 2:
nums_cnt[num] -= 2
cnt += 1
print(cnt)
return
main()
|
p03201
|
import bisect
import collections
n = int(eval(input()))
a = list(map(int, input().split()))
a_counter = collections.Counter(a)
a_keys = sorted(list(a_counter.keys()), reverse=True)
targets = []
t = 0
vt = 1
for v in a:
while v >= vt:
t += 1
vt *= 2
targets.append(vt)
targets.reverse()
cnt = 0
for key in a_keys:
if a_counter[key] <= 0:
continue
for t in targets:
if key == t-key:
p = max(0, min(a_counter[key], a_counter[t-key])) // 2
else:
p = max(0, min(a_counter[key], a_counter[t-key]))
a_counter[key] -= p
a_counter[t-key] -= p
cnt += p
print(cnt)
|
import bisect
import collections
n = int(eval(input()))
a = list(map(int, input().split()))
a_counter = collections.Counter(a)
a_keys = sorted(list(a_counter.keys()), reverse=True)
targets = []
t = 0
vt = 1
for v in a:
while v >= vt:
t += 1
vt *= 2
targets.append(vt)
targets.reverse()
cnt = 0
for key in a_keys:
if a_counter[key] <= 0:
continue
for t in targets:
if key >= t:
break
if key == t-key:
p = max(0, min(a_counter[key], a_counter[t-key])) // 2
else:
p = max(0, min(a_counter[key], a_counter[t-key]))
a_counter[key] -= p
a_counter[t-key] -= p
cnt += p
print(cnt)
|
p03201
|
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort(reverse=True)
u = [0 for i in range(len(a))]
def binarySearch(alist, item,exhi):
first = 0
last = len(alist)-1
found = False
while first<=last and not found:
midpoint = (first + last)//2
if alist[midpoint] == item and u[midpoint] <= 0 and midpoint != exhi:
found = True
u[midpoint] += 1
else:
if item > alist[midpoint]:
last = midpoint-1
else:
first = midpoint+1
return found
b = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536,
131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432,
67108864, 134217728, 268435456, 536870912]
sum = 0
i = 0
#print(a)
while True:
if u[i] > 0:
i = i + 1
if i >= len(a)-1:
break
continue
t = 0
for bb in b :
if bb > a[i]:
t = bb - a[i]
break
if t > a[i]:
i = i + 1
if i >= len(a)-1:
break
continue
if t in a :
idx = 0
while True:
try:
idx = a.index(t,idx)
if u[idx] == 0 and idx != i:
u[idx] += 1
sum += 1
break
elif idx == i:
break
except:
break
i = i + 1
if i >= len(a)-1:
break
print(sum)
|
from bisect import bisect_left
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
#print(a)
sum = 0
for i in range (len(a)-1,-1,-1):
b = 1
while b <= a[i]:
b = b<<1
t = b - a[i]
#print("2^",t)
k = bisect_left(a,t)
if a[k] == t and k < i:
sum += 1
a[k] -= 0.1
a[i] += 0.1
print(sum)
|
p03201
|
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
dic = {}
for v in a:
if v in dic:
dic[v] += 1
else:
dic[v] = 1
key = [v for v in list(dic.keys())]
key.sort(reverse=True)
ans = 0
for v in key:
num = dic[v]
if num > 0:
for i in reversed(list(range(1, 35))):
target = 2**i
if 2*v < target or target < v:
continue
u = target - v
if v == u:
z = dic[v]//2
ans += z
dic[v] -= 2*z
elif u in dic:
x, y = dic[v], dic[u]
z = 0
if x < y:
z = x
else:
z = y
dic[v] -= z
dic[u] -= z
ans += z
if dic[v] == 0:
break
print(ans)
if __name__ == "__main__":
main()
|
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
dic = {}
for v in a:
if v in dic:
dic[v] += 1
else:
dic[v] = 1
key = [v for v in list(dic.keys())]
key.sort(reverse=True)
ans = 0
for v in key:
num = dic[v]
if num > 0:
for i in reversed(list(range(1, 32))):
target = 2**i
if 2*v < target:
continue
if target < v:
break
u = target - v
if v == u:
z = dic[v]//2
ans += z
dic[v] -= 2*z
elif u in dic:
x, y = dic[v], dic[u]
z = 0
if x < y:
z = x
else:
z = y
dic[v] -= z
dic[u] -= z
ans += z
if dic[v] == 0:
break
print(ans)
if __name__ == "__main__":
main()
|
p03201
|
import bisect
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort()
ans = 0
L=0
t=31
while(t>0):
if len(A) == 0:
break
if A[-1] >= (1 << t):
t -= 1
L = 0
continue
if A[-1] < (1 << (t-1)):
t -= 1
L = 0
continue
large = A.pop(-1)
tmp = bisect.bisect_left(A,(1<<t)-large,lo=L,hi=len(A))
if tmp == len(A):
t -= 1
L = 0
continue
if A[tmp] == (1<<t)-large:
del A[tmp]
ans += 1
L = max(0,tmp-1)
print(ans)
|
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort(reverse=True)
dic = {}
for a in A:
dic[a] = dic.get(a,0)+1
ans = 0
for a in A:
small = (1<<(len(format(a,"b")))) - a
if small == a:
if dic[a] >= 2:
dic[a] -= 2
ans += 1
continue
if dic.get(a,0)>0 and dic.get(small,0)>0:
dic[a] -= 1
dic[small] -= 1
ans += 1
print(ans)
|
p03201
|
from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
cnt = defaultdict(int)
for a in A:
cnt[a] += 1
n = 1
while n <= 2 * A[0]:
n *= 2
n //= 2
ans = 0
while n > 0:
for a in A:
if cnt[a] == 0:
continue
b = n - a
if b > a:
break
c = 0
if b == a and cnt[a] > 1:
c = cnt[a] // 2
elif b != a and cnt[b] > 0:
c = min(cnt[a], cnt[b])
cnt[a] -= c
cnt[b] -= c
ans += c
n //= 2
print(ans)
|
from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
cnt = defaultdict(int)
for a in A:
cnt[a] += 1
n = 1
while n <= 2 * A[0]:
n *= 2
n //= 2
ans = 0
while n > 0:
for a in A:
if cnt[a] == 0:
continue
b = n - a
if b < 0:
continue
if b > a:
break
c = 0
if b == a and cnt[a] > 1:
c = cnt[a] // 2
elif b != a and cnt[b] > 0:
c = min(cnt[a], cnt[b])
cnt[a] -= c
cnt[b] -= c
ans += c
n //= 2
print(ans)
|
p03201
|
import math
import bisect
N=int(eval(input()))
alist=list(map(int,input().split()))
alist.sort()
#print(alist)
flist=[False]*N
answer=0
for i in reversed(list(range(N))):
if flist[i]:
continue
p1=alist[i]
p2=2**math.ceil(math.log(p1+1,2))-p1
#print(p1,p2)
index1 = bisect.bisect_left(alist,p2,0,i+1)
index2 = bisect.bisect_right(alist,p2,index1,i+1)
#print(index1,index2)
for j in range(index1,index2):
if j != i and not flist[j]:
flist[i]=True
flist[j]=True
answer+=1
break
#print(flist)
print(answer)
|
import bisect
N=int(eval(input()))
alist=list(map(int,input().split()))
alist.sort(reverse=True)
blist=[]
for a in alist:
a2=a
digit_a2=0
while(a2>0):
a2>>=1
digit_a2+=1
b=2**(digit_a2)-a
blist.append(b)
#print(alist)
#print(blist)
dic_a={}
for a in alist:
if a in dic_a:
dic_a[a]+=1
else:
dic_a[a]=1
answer=0
for i in range(N):
a=alist[i]
b=blist[i]
if a==b:
if dic_a[a]>1:
dic_a[a]-=2
answer+=1
#print(a,a)
else:
if dic_a[a]>0 and b in dic_a and dic_a[b]>0:
dic_a[a]-=1
dic_a[b]-=1
answer+=1
#print(a,b)
print(answer)
|
p03201
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.