input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
import heapq
def dijkstra_heap(s):
#始点sから各頂点への最短距離
d = [float("inf")] * n
used = [True] * n #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for e in edge[s]:
heapq.heappush(edgelist, e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist, [e[0] + d[v], e[1]])
return d
################################
n, x, y = list(map(int, input().split())) #n:頂点数
w = n
edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w - 1):
edge[i + 1].append([1, i])
edge[i].append([1, i + 1])
edge[x - 1].append([1, y - 1])
edge[y - 1].append([1, x - 1])
dic = {i: 0 for i in range(1, n)}
for i in range(n):
tmp = dijkstra_heap(i)
zero = False
for j in tmp:
if zero:
dic[j] += 1
if j == 0:
zero = True
for i in range(1, n):
print((dic[i]))
|
n, x, y = list(map(int, input().split()))
dic = {i: 0 for i in range(1, n)}
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
dist = min(j - i, abs(i - x) + abs(j - y) + 1)
dic[dist] += 1
for i in range(1, n):
print((dic[i]))
|
p02726
|
n,x,y=list(map(int,input().split()))
a=[[0 for _ in range(n)] for _ in range(n)]
ans=[0 for _ in range(n-1)]
for i in range(n-1):
for j in range(i+1,n):
t=i+1
u=j+1
a[i][j]=min(abs(u-t),abs(t-x)+1+abs(y-u),abs(t-y)+1+abs(x-u))
X=a[i][j]
ans[X-1]+=1
for l in ans:
print(l)
|
n,x,y=list(map(int,input().split()))
ans=[0 for _ in range(n-1)]
for i in range(n-1):
for j in range(i+1,n):
t=i+1
u=j+1
H=min(abs(u-t),abs(t-x)+1+abs(y-u),abs(t-y)+1+abs(x-u))
ans[H-1]+=1
for l in ans:
print(l)
|
p02726
|
##?
n,x,y = list(map(int,input().split( )))
x-=1;y-=1
cnt = [0]*n
for i in range(n):
for j in range(i+1,n):
dist = min(abs(j-i),abs(x-i)+1+abs(j-y))
cnt[dist]+=1
for i in range(1,n):
print((cnt[i]))
|
n,x,y=list(map(int, input().split()))
cnts=[0]*n
for i in range(1,n+1):
for j in range(1,i):
mn=min(abs(i-j),abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
cnts[mn]+=1
for ci in cnts[1:]:
print(ci)
|
p02726
|
def resolve():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
from collections import defaultdict, deque
matrix = [[0]*N for _ in range(N)]
for i in range(N-1):
matrix[i][i+1] = matrix[i+1][i] = 1
matrix[X][Y] = matrix[Y][X] = 1
ans = [0] * N
for i in range(N):
queue = deque([(i, 0)])
d = [float('inf')] * N
while queue:
node, dist = queue.popleft()
if d[node] != float('inf'):
continue
d[node] = dist
for adj in range(N):
if matrix[node][adj]:
queue.append([adj, dist+1])
for j in range(N):
ans[d[j]] += 1
for i in range(1, N):
print((ans[i]//2))
resolve()
|
def resolve():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
from collections import defaultdict, deque
matrix = defaultdict(list)
for i in range(N-1):
matrix[i].append(i+1)
matrix[i+1].append(i)
matrix[X].append(Y)
matrix[Y].append(X)
ans = [0] * N
for i in range(N):
queue = deque([(i, 0)])
d = [float('inf')] * N
while queue:
node, dist = queue.popleft()
if d[node] != float('inf'):
continue
d[node] = dist
for adj in matrix[node]:
queue.append([adj, dist+1])
for j in range(N):
ans[d[j]] += 1
for i in range(1, N):
print((ans[i]//2))
resolve()
|
p02726
|
# -*= coding: utf-8 -*-
import queue
N, X, Y = list(map(int, input().split()))
q = queue.Queue()
ans = [0] * N
# BFS
for i in range(N):
# 0 〜 N-1の各頂点からスタート
cost = [-1] * N
cost[i] = 0
q.put(i) # 基準とする頂点をノードiにする
while not q.empty():
# 現在のノードのインデックス
current = q.get()
if current - 1 >= 0 and cost[current - 1] == -1:
# 1つ前のノードを登録
q.put(current - 1)
cost[current - 1] = cost[current] + 1
if current + 1 < N and cost[current + 1] == -1:
# 1つ後ろのノードを登録
q.put(current + 1)
cost[current + 1] = cost[current] + 1
if current == X - 1 and cost[Y - 1] == -1:
# XからYへのルートを登録
q.put(Y - 1)
cost[Y - 1] = cost[current] + 1
if current == Y - 1 and cost[X - 1] == -1:
# YからXへのルートを登録
q.put(X - 1)
cost[X - 1] = cost[current] + 1
# この時点でcostにはノードiから各ノードへの最小コストが格納されている
#print(cost)
for j in range(N):
ans[cost[j]] += 1
for i in range(1, N):
print((ans[i]//2)) # ノードA→Bと、逆向きのB→Aが、両方カウントされているので2分の1する
|
# -*= coding: utf-8 -*-
from collections import deque
N, X, Y = list(map(int, input().split()))
d = deque() # 初期化
ans = [0] * N
# BFS
for i in range(N):
# 0 〜 N-1の各頂点からスタート
cost = [-1] * N
cost[i] = 0
d.append(i) # 基準とする頂点をノードiにする
while len(d) > 0:
# dequeueが空でない間ループ
# 現在のノードのインデックス
current = d.popleft()
if current - 1 >= 0 and cost[current - 1] == -1:
# 1つ前のノードを登録
d.append(current - 1)
cost[current - 1] = cost[current] + 1
if current + 1 < N and cost[current + 1] == -1:
# 1つ後ろのノードを登録
d.append(current + 1)
cost[current + 1] = cost[current] + 1
if current == X - 1 and cost[Y - 1] == -1:
# XからYへのルートを登録
d.append(Y - 1)
cost[Y - 1] = cost[current] + 1
if current == Y - 1 and cost[X - 1] == -1:
# YからXへのルートを登録
d.append(X - 1)
cost[X - 1] = cost[current] + 1
# この時点でcostにはノードiから各ノードへの最小コストが格納されている
#print(cost)
for j in range(N):
ans[cost[j]] += 1
for i in range(1, N):
print((ans[i]//2)) # ノードA→Bと、逆向きのB→Aが、両方カウントされているので2分の1する
|
p02726
|
from itertools import combinations as cb
node = []
n,x,y = list(map(int, input().split()))
for i in range(1, n+1):
node.append(i)
pair = list(cb(node, 2))
dist = [0]*n
for a in pair:
if a[1] <= x or a[0] >= y:
dist[a[1]-a[0]] += 1
else:
dist[min(abs(x-a[0])+abs(y-a[1])+1,a[1]-a[0])] += 1
for i in range(1, n):
print((dist[i]))
|
from itertools import combinations as cb
n,x,y = list(map(int, input().split()))
pair = list(cb(list(range(1,n+1)), 2))
dist = [0]*n
for a in pair:
if a[1] <= x or a[0] >= y:
dist[a[1]-a[0]] += 1
else:
dist[min(abs(x-a[0])+abs(y-a[1])+1,a[1]-a[0])] += 1
for i in range(1, n):
print((dist[i]))
|
p02726
|
from collections import deque
# 全部ゼロ始まり
n, x, y = list(map(int, input().split()))
G = [[] for _ in range(n)]
for i in range(n-1):
G[i].append(i+1)
for i in range(1, n):
G[i].append(i-1)
x -= 1
y -= 1
G[x].append(y)
G[y].append(x)
# iとjの最短距離を返す
def bfs(i, j):
i -= 1
j -= 1
q = deque()
seen = [False] * n
dist = [-1] * n
q.append(i)
seen[i] = True
dist[i] = 0
while len(q) > 0:
now_v = q.popleft()
for new_v in G[now_v]:
if seen[new_v] is True:
continue
q.append(new_v)
seen[new_v] = True
dist[new_v] = dist[now_v] + 1
if new_v == j:
return dist[j]
cnt = [0] * (n-1)
for i in range(n-1):
for j in range(i+1, n):
cnt[bfs(i, j)-1] += 1
for ans in cnt:
print(ans)
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
cnt = [0] * n
for i in range(n-1):
for j in range(i+1, n):
direct = j - i
detour = abs(x-i) + abs(y-j) + 1
d = min(direct, detour)
cnt[d] += 1
for k in range(1, n):
print((cnt[k]))
|
p02726
|
# Author: cr4zjh0bp
# Created: Sat Mar 28 11:53:27 UTC 2020
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
from collections import defaultdict, deque
n, x, y = na()
x -= 1
y -= 1
d = defaultdict(int)
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)
def bfs(i):
q = deque()
q.append(i)
dist = [-1] * n
dist[i] = 0
while len(q):
p = q.popleft()
for j in g[p]:
if dist[j] != -1:
continue
dist[j] = dist[p] + 1
q.append(j)
return dist
dic = defaultdict(int)
for i in range(n):
d = bfs(i)
for j in range(n):
dic[d[j]] += 1
for i in range(1, n):
print((dic[i] // 2))
|
# Author: cr4zjh0bp
# Created: Sat Mar 28 11:53:27 UTC 2020
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
from collections import defaultdict
n, x, y = na()
x -= 1
y -= 1
dic = defaultdict(int)
for i in range(n):
for j in range(i + 1, n):
dist = min(j - i, 1 + abs(x - i) + abs(y - j))
dic[dist] += 1
for i in range(1, n):
print((dic[i]))
|
p02726
|
# D - Line++
import queue
N, X, Y = list(map(int, input().split()))
X, Y = X - 1, Y - 1
M = [(i, []) for i in range(N)]
for i in range(N):
if i != 0:
M[i][1].append(i - 1)
if i != N - 1:
M[i][1].append(i + 1)
if i == X:
M[X][1].append(Y)
if i == Y:
M[Y][1].append(X)
cost = [[-1] * N for _ in range(N)]
p = [[None] * N for _ in range(N)]
Q = queue.Queue()
for i in range(N):
Q.put(M[i])
key = M[i][0]
cost[key][key] = 0
p[key][key] = key
while not Q.empty():
q = Q.get()
for j in q[1]:
if cost[i][j] == -1:
p[i][j] = q[0]
cost[i][j] = cost[i][p[i][j]] + 1
Q.put(M[j])
ans = [0] * N
for i in range(N):
for j in range(N):
ans[cost[i][j]] += 1
for i in range(1, N):
print((int(ans[i] / 2)))
|
# D - Line++
n, x, y = list(map(int, input().split()))
x, y = x - 1, y - 1
cnt = [0] * n
for i in range(n):
for j in range(i + 1, n):
dist = min(j - i, abs(x - i) + abs(y - j) + 1)
cnt[dist] += 1
for i in range(1, len(cnt)):
print((cnt[i]))
|
p02726
|
import math
N, X, Y = list(map(int, input().split()))
distnum = [0 for i in range(N)]
dist = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1, N+1):
for j in range(i, N+1):
dist[i][j] = min(abs(X-i) + 1 + abs(Y-j), abs(X-j)+1+abs(Y-i), abs(i-j))
distnum[dist[i][j]] += 1
for i in range(1, N):
print((distnum[i]))
|
import math
N, X, Y = list(map(int, input().split()))
distnum = [0 for i in range(N)]
for i in range(1, N+1):
for j in range(i, N+1):
dist = min(abs(X-i) + 1 + abs(Y-j), abs(X-j)+1+abs(Y-i), abs(i-j))
distnum[dist] += 1
for i in range(1, N):
print((distnum[i]))
|
p02726
|
N, X, Y = list(map(int,input().split()))
k_list = [0]*N
for p in range(1, N):
for q in range(p, N+1):
p2X = abs(p - X)
p2Y = abs(p - Y)
q2X = abs(q - X)
q2Y = abs(q - Y)
distance = min(q-p, p2X+1+q2Y)
k_list[distance] += 1
for k in range(1, N):
print((k_list[k]))
|
N, X, Y = list(map(int,input().split()))
k_list = [0]*N
for p in range(1, N):
for q in range(p, N+1):
p2X = abs(p - X)
q2Y = abs(q - Y)
distance = min(q-p, p2X+1+q2Y)
k_list[distance] += 1
for k in range(1, N):
print((k_list[k]))
|
p02726
|
from collections import deque
def bfs(start):
global count
d = [float('inf') for i in range(N)]
d[start] = 0
que = deque()
que.append(start)
alr = [start]
while que:
q = que.popleft()
c = d[q]
for i in path[q]:
if i not in alr:
que.append(i)
alr.append(i)
d[i] = c+1
for i in range(start+1,N):
count[d[i]-1] += 1
N,X,Y = list(map(int,input().split()))
path = [[] for i in range(N)]
path[0] = [1]
path[N-1] = [N-2]
for i in range(1,N-1):
path[i] = [i-1,i+1]
path[X-1].append(Y-1)
path[Y-1].append(X-1)
count = [0 for i in range(N-1)]
for i in range(N-1):
bfs(i)
for i in range(N-1):
print((count[i]))
|
N,X,Y = list(map(int,input().split()))
ans = [0 for i in range(N-1)]
for i in range(1,N):
for j in range(i+1,N+1):
mina = min(j-i, abs(X-i)+1+abs(Y-j), abs(Y-i)+1+abs(X-j))
ans[mina-1] += 1
for i in ans:
print(i)
|
p02726
|
from heapq import heappush, heappop
from collections import deque
n, x, y = list(map(int, input().split()))
G = [[]*n for _ in range(n)]
for i in range(n-1):
G[i].append((i+1, 1))
G[i+1].append((i, 1))
G[x-1].append((y-1, 1))
G[y-1].append((x-1, 1))
# print(G)
INF = 10**30
N = n
# s: 開始頂点
# N: 頂点数
# G: グラフ
# G[v][i] = (w, d): 辺v-wのコストは d (0 or 1)
dd = []
for i in range(n):
s = i
dist = [10**9] * N
S = deque([s])
T = deque()
dist[s] = 0
d = 0
while S:
while S:
v = S.popleft()
for w, c in G[v]:
if d+c < dist[w]:
dist[w] = d+c
if c:
T.append(w)
else:
S.append(w)
S, T = T, S
d += 1
dd.append(dist)
for i in range(1, n):
ans = 0
for d in dd:
ans += d.count(i)
print((ans//2))
|
from collections import defaultdict
from heapq import heappush, heappop
from collections import deque
n, x, y = list(map(int, input().split()))
G = [[]*n for _ in range(n)]
for i in range(n-1):
G[i].append((i+1, 1))
G[i+1].append((i, 1))
G[x-1].append((y-1, 1))
G[y-1].append((x-1, 1))
# print(G)
INF = 10**30
N = n
# s: 開始頂点
# N: 頂点数
# G: グラフ
# G[v][i] = (w, d): 辺v-wのコストは d (0 or 1)
dd = []
for i in range(n):
s = i
dist = [10**9] * N
S = deque([s])
T = deque()
dist[s] = 0
d = 0
while S:
while S:
v = S.popleft()
for w, c in G[v]:
if d+c < dist[w]:
dist[w] = d+c
if c:
T.append(w)
else:
S.append(w)
S, T = T, S
d += 1
dd.append(dist)
ans = defaultdict(lambda: 0)
for dist in dd:
for t in dist:
ans[t] += 1
for i in range(n-1):
print((ans[i+1]//2))
|
p02726
|
N,X,Y=list(map(int,input().split()))
X-=1
Y-=1
dist=[0]*(N+1)
for i in range(N):
for j in range(N):
dist[(min(abs(i-j),abs(i-Y)+abs(X-j)+1,abs(i-X)+abs(Y-j)+1))]+=1
for d in range(1,N):
print((dist[d]//2))
|
N,X,Y=list(map(int,input().split()))
X-=1
Y-=1
dist=[0]*(N+1)
for i in range(N):
for j in range(i+1,N):
dist[(min(abs(i-j),abs(i-Y)+abs(X-j)+1,abs(i-X)+abs(Y-j)+1))]+=1
for d in range(1,N):
print((dist[d]))
|
p02726
|
def dijkstra(s,n,w,cost, pre):
#始点sから各頂点への最短距離
#n:頂点数, w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
d = [float("inf")] * n
for i in range(len(pre)):
d[i] = pre[i]
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(len(pre), n):
d[j] = min(d[j],d[v]+cost[v][j])
return d
n, a, b = list(map(int, input().split()))
cost = [[float("inf") for i in range(n)] for i in range(n)]
for i in range(n-1):
# x,y,z = map(int,input().split())
# cost[x][y] = z
# cost[y][x] = z
cost[i][i+1] = 1
cost[i+1][i] = 1
cost[a-1][b-1] = 1
cost[b-1][a-1] = 1
ANS = []
for i in range(n):
pre = []
for j in range(i):
pre.append(ANS[j][i])
ANS.append(dijkstra(i, n, n, cost, pre))
# print(ANS)
from functools import reduce
A = reduce(lambda x,y: x+y,ANS)
import collections
c = collections.Counter(A)
for i in range(1, n):
print((c[i]//2))
|
a, b, c = list(map(int, input().split()))
b = b - 1
c = c - 1
A = []
for i in range(a):
for j in range(i+1, a):
A.append(min(abs(i - b) + 1 + abs(j - c), abs(j - i)))
import collections
C = collections.Counter(A)
for i in range(1, a):
print((C[i]))
|
p02726
|
from collections import deque
def main():
N, X, Y = list(map(int, input().split()))
ans = [0] * N # 距離ごとの合計 [d=0, d=1, d=2, d=3, d=4]の数
X -= 1
Y -= 1
for start_vertex in range(N):
dist = [float('inf')] * N
q = deque()
def push(vertex, distance):
if dist[vertex] != float('inf'):
return
dist[vertex] = distance
q.append(vertex)
push(start_vertex, 0) # 始点をpush
while len(q) != 0:
vertex = q.popleft()
distance = dist[vertex]
if vertex - 1 >= 0:
push(vertex - 1, distance + 1)
if vertex + 1 < N:
push(vertex + 1, distance + 1)
if vertex == X:
push(Y, distance + 1)
if vertex == Y:
push(X, distance + 1)
for i in range(N):
ans[dist[i]] += 1
for i in range(N):
ans[i] //= 2
for i in range(1, N):
print((ans[i]))
if __name__ == '__main__':
main()
|
import sys
input = sys.stdin.readline
from collections import deque
def main():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
ans = [0] * N
for start_vertex in range(N):
q = deque()
distance_list = [float('inf')] * N
def push(vertex, distance):
if distance_list[vertex] != float('inf'):
return
q.append(vertex)
distance_list[vertex] = distance
push(start_vertex, 0)
while len(q) != 0:
vertex = q.popleft()
distance = distance_list[vertex]
if vertex - 1 >= 0:
push(vertex - 1, distance + 1)
if vertex + 1 < N:
push(vertex + 1, distance + 1)
if vertex == X:
push(Y, distance + 1)
if vertex == Y:
push(X, distance + 1)
for i in distance_list:
ans[i] += 1
print(('\n'.join([str(i // 2) for i in ans[1:]])))
if __name__ == '__main__':
main()
|
p02726
|
N, X, Y = input().split()
N = int(N)
X = int(X)
x = X - 1
Y = int(Y)
y = Y -1
A = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(N-i):
A[i][i + j] = min(abs(x- i) +1 +abs(y-i-j),j)
A[X-1][Y-1] = 1
ans = []
ans.append(sum(A, []))
for t in range(N):
if t == 0:
continue
sum = A.count(t)
print((ans[0].count(t)))
|
N, X, Y = input().split()
N = int(N)
X = int(X)
x = X - 1
Y = int(Y)
y = Y -1
ans = [0] * (N)
A = [[] * N for _ in range(N)]
for i in range(N):
for j in range(N-i):
path = min(abs(x- i) +1 +abs(y-i-j),j)
ans[path] += 1
for _ in range(len(ans)):
if _ == 0:
continue
print((ans[_]))
|
p02726
|
def main():
from collections import deque
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
g = tuple(set() for _ in range(N))
for v in range(N):
if v > 0:
g[v].add(v - 1)
if v < N - 1:
g[v].add(v + 1)
g[X].add(Y)
g[Y].add(X)
ctr = [0] * N
for v in range(N):
dist = [-1] * N
q = deque()
q.append((v, 0))
while q:
v, d = q.popleft()
if ~dist[v] and dist[v] < d: continue
dist[v] = d
for u in g[v]:
if ~dist[u]: continue
dist[u] = d + 1
q.append((u, d + 1))
for d in dist:
ctr[d] += 1
print(*map(lambda x: x // 2, ctr[1:]), sep='\n')
if __name__ == '__main__':
main()
|
# https://atcoder.jp/contests/abc160/submissions/11310424
def main():
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
def dist(a, b):
return min(
abs(a - b),
abs(a - X) + abs(b - Y) + 1,
abs(a - Y) + abs(b - X) + 1
)
ctr = [0] * N
for b in range(N):
for a in range(b):
d = dist(a, b)
ctr[d] += 1
print(*ctr[1:], sep='\n')
if __name__ == '__main__':
main()
|
p02726
|
# https://atcoder.jp/contests/abc160/submissions/11310424
def main():
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
def dist(a, b):
return min(
abs(a - b),
abs(a - X) + abs(b - Y) + 1,
abs(a - Y) + abs(b - X) + 1
)
ctr = [0] * N
for b in range(N):
for a in range(b):
d = dist(a, b)
ctr[d] += 1
print(*ctr[1:], sep='\n')
if __name__ == '__main__':
main()
|
# https://atcoder.jp/contests/abc160/submissions/11310424
def main():
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
def dist(a, b):
return min(
abs(a - b),
abs(a - X) + abs(b - Y) + 1,
abs(a - Y) + abs(b - X) + 1
)
ctr = [0] * N
for b in range(N):
for a in range(b):
d = dist(a, b)
ctr[d] += 1
it = iter(ctr)
next(it)
print(*it, sep='\n')
if __name__ == '__main__':
main()
|
p02726
|
def dist(a, b):
return min(
abs(a - b),
abs(a - x) + 1 + abs(y - b),
abs(a - y) + 1 + abs(x - b)
)
n, x, y = map(int, input().split())
x -= 1
y -= 1
d = [0] * n
for j in range(n):
for i in range(j):
d[dist(i, j)] += 1
it = iter(d)
next(it)
print(*it, sep='\n')
|
def main():
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
ans = [0] * N
for j in range(N):
for i in range(j):
d = min(
j - i,
abs(j - X) + 1 + abs(Y - i),
abs(j - Y) + 1 + abs(X - i)
)
ans[d] += 1
print(*ans[1:], sep='\n')
if __name__ == '__main__':
main()
|
p02726
|
import pprint
from itertools import chain
import collections
n, x, y = (int(each) for each in input().split(' '))
# table1 = [[0] * n for i in range(n)]
# table2 = [[0] * n for i in range(n)]
table_shortest = [[0] * n for i in range(n)]
# cntr = {}
# # 点iから点jまでの距離をテーブルにする
# # 抜け道を通らないルートの場合
# for i in range(n):
# for j in range(n):
# if j-i > 0:
# table1[i][j] = j-i
# # 抜け道を通るルートの場合
# for i in range(n):
# for j in range(n):
# if j-i > 0:
# table2[i][j] = abs(j-y+1)+abs(i-x+1)+1
# どちらか近いほうのルートが最短距離
for i in range(n):
for j in range(n):
if j-i > 0:
table_shortest[i][j] = min(j-i, abs(j-y+1)+abs(i-x+1)+1)
# テーブルをflattenして数をかぞえる
cntr = collections.Counter(list(chain.from_iterable(table_shortest)))
cntr = dict(cntr)
for each in range(1,n):
print((cntr.get(each, 0)))
|
import pprint
from itertools import chain
import collections
n, x, y = (int(each) for each in input().split(' '))
# table1 = [[0] * n for i in range(n)]
# table2 = [[0] * n for i in range(n)]
table = [[0] * n for i in range(n)]
# cntr = {}
# # 点iから点jまでの距離をテーブルにする
# # 抜け道を通らないルートの場合
# for i in range(n):
# for j in range(n):
# if j-i > 0:
# table1[i][j] = j-i
# # 抜け道を通るルートの場合
# for i in range(n):
# for j in range(n):
# if j-i > 0:
# table2[i][j] = abs(j-y+1)+abs(i-x+1)+1
# どちらか近いほうのルートが最短距離
for i in range(n):
for j in range(i, n):
if j-i > 0:
table[i][j] = min(j-i, abs(j-y+1)+abs(i-x+1)+1)
# テーブルをflattenして数をかぞえる
cntr = collections.Counter(list(chain.from_iterable(table)))
# cntr = dict(cntr)
for each in range(1,n):
print((cntr.get(each, 0)))
|
p02726
|
N, X, Y = map(int, input().split())
dis = [0] * (N - 1)
for i in range(1, N):
for j in range(i + 1, N + 1):
cmb = min(j - i, min(abs(X - i) + 1 + abs(Y - j), abs(Y - i) + 1 + abs(X - j)))
dis[cmb - 1] += 1
[print(i) for i in dis]
|
N, X, Y = map(int, input().split())
dis = [0] * (N - 1)
for i in range(1, N):
for j in range(i + 1, N + 1):
cmb = min(j - i, abs(X - i) + 1 + abs(Y - j), abs(Y - i) + 1 + abs(X - j))
dis[cmb - 1] += 1
[print(i) for i in dis]
|
p02726
|
from collections import deque, defaultdict
n, x, y = list(map(int, input().split()))
inf = 10**10
dp = [[inf]*n for _ in range(n)]
dic = defaultdict(int)
pas = defaultdict(list)
for i in range(n):
l=1
dp[i][i] = 0
if i==0 and x==1:
queue = deque([1, y-1])
dp[i][1]=1
dp[i][y-1]=1
dic[1]+=2
elif i==0:
queue = deque([1])
dp[i][1]=1
dic[1]+=1
elif i==n-1 and y==n:
queue = deque([n-2, x-1])
dp[i][n-2]=1
dp[i][x-1]=1
dic[1]+=2
elif i==n-1:
queue = deque([n-2])
dp[i][n-2]=1
dic[1]+=1
elif i==x-1:
queue = deque([i-1, i+1, y-1])
dp[i][i+1]=1
dp[i][i-1]=1
dp[i][y-1]=1
dic[1]+=3
elif i==y-1:
queue = deque([i-1, i+1, x-1])
dp[i][i+1]=1
dp[i][i-1]=1
dp[i][x-1]=1
dic[1]+=3
else:
queue = deque([i-1, i+1])
dp[i][i-1]=1
dp[i][i+1]=1
dic[1]+=2
while queue:
t = queue.popleft()
#dic[]+=1
if t == x-1 and dp[i][y-1]==inf:
queue.append(y-1)
dp[i][y-1]=dp[i][t]+1
dic[dp[i][t]+1]+=1
if t == y-1 and dp[i][x-1]==inf:
queue.append(x-1)
dp[i][x-1]=dp[i][t]+1
dic[dp[i][t]+1]+=1
if not t==0:
if dp[i][t-1]==inf:
queue.append(t-1)
dp[i][t-1]=dp[i][t]+1
dic[dp[i][t]+1]+=1
if not t==n-1:
if dp[i][t+1]==inf:
queue.append(t+1)
dp[i][t+1]=dp[i][t]+1
dic[dp[i][t]+1]+=1
for i in range(1, n):
print((dic[i]//2))
|
from collections import deque, defaultdict
n, x, y = list(map(int, input().split()))
inf = 10**10
dp = [[inf]*n for _ in range(n)]
dic = defaultdict(int)
for i in range(n):
l=1
dp[i][i] = 0
if i==0 and x==1:
queue = deque([1, y-1])
dp[i][1]=1
dp[i][y-1]=1
dic[1]+=2
elif i==0:
queue = deque([1])
dp[i][1]=1
dic[1]+=1
elif i==n-1 and y==n:
queue = deque([n-2, x-1])
dp[i][n-2]=1
dp[i][x-1]=1
dic[1]+=2
elif i==n-1:
queue = deque([n-2])
dp[i][n-2]=1
dic[1]+=1
elif i==x-1:
queue = deque([i-1, i+1, y-1])
dp[i][i+1]=1
dp[i][i-1]=1
dp[i][y-1]=1
dic[1]+=3
elif i==y-1:
queue = deque([i-1, i+1, x-1])
dp[i][i+1]=1
dp[i][i-1]=1
dp[i][x-1]=1
dic[1]+=3
else:
queue = deque([i-1, i+1])
dp[i][i-1]=1
dp[i][i+1]=1
dic[1]+=2
while queue:
t = queue.popleft()
#dic[]+=1
if t == x-1 and dp[i][y-1]==inf:
queue.append(y-1)
dp[i][y-1]=dp[i][t]+1
dic[dp[i][t]+1]+=1
if t == y-1 and dp[i][x-1]==inf:
queue.append(x-1)
dp[i][x-1]=dp[i][t]+1
dic[dp[i][t]+1]+=1
if not t==0:
if dp[i][t-1]==inf:
queue.append(t-1)
dp[i][t-1]=dp[i][t]+1
dic[dp[i][t]+1]+=1
if not t==n-1:
if dp[i][t+1]==inf:
queue.append(t+1)
dp[i][t+1]=dp[i][t]+1
dic[dp[i][t]+1]+=1
for i in range(1, n):
print((dic[i]//2))
|
p02726
|
n,x,y=list(map(int,input().split()))
s=[]
for i in range(1,n):
for j in range(i+1,n+1):
s.append(min(j-i,abs(x-j)+1+abs(y-i),abs(x-i)+1+abs(y-j)))
for l in range(1,n):
print((s.count(l)))
|
n,x,y=list(map(int,input().split()))
res=[0]*n
for i in range(1,n):
for j in range(i+1,n+1):
s=(min(j-i,abs(x-j)+1+abs(y-i),abs(x-i)+1+abs(y-j)))
res[s]+=1
for k in range(1,n):
print((res[k]))
|
p02726
|
from collections import deque
def dfs(rel, s):
dist = [-1] * len(rel)
q = deque()
q.append(s)
dist[s] = 0
while len(q):
e = q.popleft()
for ei in Rel[e]:
if dist[ei] >= 0:
continue
q.append(ei)
dist[ei] = dist[e] + 1
ans = [0] * (len(rel) - 1)
for d in dist:
ans[d] += 1
return ans
N, X, Y = list(map(int, input().split()))
Rel = [None] + [[] for _ in range(N)]
for i in range(1, N + 1):
if i > 1:
Rel[i].append(i - 1)
if i < N:
Rel[i].append(i + 1)
Rel[X].append(Y)
Rel[Y].append(X)
K = [0] * (N - 1)
for i in range(1, N + 1):
dist = dfs(Rel, i)
for k, v in enumerate(dist[1:]):
K[k] += v
for k in K[:-1]:
print((k // 2))
print((0))
|
N, X, Y = list(map(int, input().split()))
D = [None] + [0] * (N - 1)
for i in range(1, N):
for j in range(i + 1, N + 1):
d = min(abs(j - i),
abs(X - i) + 1 + abs(j - Y),
abs(Y - i) + 1 + abs(j - X))
D[d] += 1
for d in D[1:]:
print(d)
|
p02726
|
# coding: utf-8
from collections import deque
def main():
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
D = [[float("inf") for _ in range(N)] for _ in range(N)]
D[X][Y] = 1
D[Y][X] = 1
queue = deque([[X, Y]])
visited = [[False for _ in range(N)] for _ in range(N)]
visited[X][Y] = True
while queue:
x,y = queue.popleft()
for i, j in zip([1, 0, -1, 0], [0, 1, 0, -1]):
nx, ny = x+i, y+j
if nx < 0 or nx >= N or ny < 0 or ny >= N:
continue
if visited[nx][ny]:
continue
else:
visited[nx][ny] = True
D[nx][ny] = min(abs(ny-nx), D[x][y]+1)
queue.append([nx, ny])
ans = [0 for _ in range(N)]
cnt = 0
for i in range(N):
for j in range(i+1, N):
v = D[i][j]
ans[v-1] += 1
print(*ans[:-1], sep="\n")
main()
|
# coding: utf-8
from collections import deque
def main():
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
D = [[0 for _ in range(N)] for _ in range(N)]
D[X][Y] = 1
D[Y][X] = 1
queue = deque([[X, Y]])
visited = [[False for _ in range(N)] for _ in range(N)]
visited[X][Y] = True
while queue:
x,y = queue.popleft()
for i, j in zip([1, 0, -1, 0], [0, 1, 0, -1]):
nx, ny = x+i, y+j
if nx < 0 or nx >= N or ny < 0 or ny >= N:
continue
if visited[nx][ny]:
continue
else:
visited[nx][ny] = True
D[nx][ny] = min(abs(ny-nx), D[x][y]+1)
queue.append([nx, ny])
ans = [0 for _ in range(N)]
cnt = 0
for i in range(N):
for j in range(i+1, N):
v = D[i][j]
ans[v-1] += 1
print(*ans[:-1], sep="\n")
main()
|
p02726
|
n,x,y = list(map(int, input().split()))
ans = [0]*(n)
for i in range(n-1):
for j in range(i+1, n):
r1 = min(j-i, (abs(x-i-1) + 1 + abs(y-j-1) ), (abs(y-i-1) + 1 + abs(x-j-1) ) )
ans[r1] += 1
for i in ans[1:]:
print(i)
|
n,x,y = list(map(int, input().split()))
ans = [0]*(n)
for i in range(n-1):
for j in range(i+1, n):
#r1 = min(j-i, (abs(x-i-1) + 1 + abs(y-j-1) ), (abs(y-i-1) + 1 + abs(x-j-1) ) )
r1 = min(j - i, (abs(x - i - 1) + 1 + abs(y - j - 1)))
ans[r1] += 1
for i in ans[1:]:
print(i)
|
p02726
|
n,x,y=list(map(int,input().split()))
x,y=x-1,y-1
adj=[[float("inf")]*n for i in range(n)]
for i in range(n):
for j in range(n):
adj[i][j]=abs(i-j)
adj[x][y]=adj[y][x]=1
for i in range(n):
for j in range(n):
for k in range(n):
adj[j][k]=min(adj[j][k],adj[j][i]+adj[i][k])
ans=[0 for i in range(n)]
for i in range(n-1):
for j in range(i+1,n):
ans[adj[i][j]]+=1
for i in range(1,n):
print((ans[i]))
|
n,x,y=list(map(int,input().split()))
x,y=x-1,y-1
adj=[[float("inf")]*n for i in range(n)]
adj[x][y]=adj[y][x]=1
for i in range(n):
for j in range(n):
adj[i][j]=min(abs(i-j),abs(i-x)+1+abs(y-j),abs(i-y)+1+abs(y-j))
ans=[0 for i in range(n)]
for i in range(n-1):
for j in range(i+1,n):
ans[adj[i][j]]+=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(1, n+1):
r = min(
abs(i-j),
abs(x-i) + 1 + abs(y-j),
abs(y-i) + 1 + abs(x-j)
)
if r > n-1:
continue
ans[r] += 1
print(("\n".join([str(u//2) for u in ans[1:]])))
|
n, x, y = list(map(int, input().split()))
ans = [0] * n
for i in range(1, n+1):
for j in range(i, n+1):
r = min(
abs(i-j),
abs(x-i) + 1 + abs(y-j),
abs(y-i) + 1 + abs(x-j)
)
ans[r] += 1
print(("\n".join(map(str, ans[1:]))))
|
p02726
|
from collections import deque, Counter
N, X, Y = list(map(int, input().split()))
G = [[0]*N for _ in range(N)]
for i in range(N-1):
G[i][i+1] = 1
G[i+1][i] = 1
G[X-1][Y-1] = 1
G[Y-1][X-1] = 1
def bfs():
C = Counter([i+1 for i in range(N)])
for i in range(N):
color = ['W']*N
D = [10**5]*N
D[i] = 0
color[i] = 'B'
Q = deque([])
Q.append(i)
idx = 1
while Q:
q = Q.popleft()
for j in range(N):
if q == j:
continue
if G[q][j] == 1 and color[j] != 'B':
color[j] = 'G'
D[j] = min(D[q]+1, D[j])
Q.append(j)
color[q] = 'B'
for d in D:
C[d] += 1
return C
C = bfs()
for k in range(1, N):
ans = C[k]//2
print(ans)
|
N, X, Y = map(int, input().split())
ans = [0]*(N-1)
for i in range(1, N):
for j in range(i+1, N+1):
d = min(j-i, abs(X-i)+abs(j-Y)+1)
ans[d-1] += 1
print(*ans, sep='\n')
|
p02726
|
import itertools
N, X, Y = list(map(int, input().split()))
result = []
for i in range(1, N+1):
for j in range(i, N+1):
result.append(min(abs(j-i), abs(X-i) + 1 + abs(j-Y), abs(Y-i)+1+abs(j-X)))
for i in range(1, N):
print((result.count(i)))
|
import itertools
N, X, Y = list(map(int, input().split()))
# dp = [[float('inf')] * (N+1) for _ in range(N+1)]
# # dp[Y][X] = 1
# dp[X][Y] = 1
# for i in range(1,N+1):
# for j in range(i,N+1):
# if i == j:
# dp[i][j] = 0
# elif i == X and j == Y:
# dp[X][Y] = 1
# elif i <= X:
# dp[i][j] = min(dp[i][j-1] + 1, dp[i][X] + abs(Y - j) + 1)
# else:
# dp[i][j] = min(dp[i][j-1]+ 1, abs(i - X)+ abs(Y - j) + 1 )
# dp = list(itertools.chain.from_iterable(dp))
# for i in range(1,N):
# print(dp.count(i))
result = [0] * N
for i in range(1, N):
for j in range(i+1, N+1):
dist = min(abs(j-i), abs(X-i) + 1 + abs(j-Y), abs(Y-i)+1+abs(j-X))
result[dist] += 1
for i in range(1, N):
print((result[i]))
|
p02726
|
n,x,y = list(map(int,input().split()))
import heapq
def dijkstra(s):
hq = [(0, s)]
heapq.heapify(hq) # リストを優先度付きキューに変換
cost = [float('inf')] * n # 行ったことのないところはinf
cost[s] = 0 # 開始地点は0
while hq:
c, v = heapq.heappop(hq)
if c > cost[v]: # コストが現在のコストよりも高ければスルー
continue
for d, u in e[v]:
tmp = d + cost[v]
if tmp < cost[u]:
cost[u] = tmp
heapq.heappush(hq, (tmp, u))
return cost
e = [[] for _ in range(n)]
for i in range(n-1):
e[i].append((1, i+1))
e[i+1].append((1, i)) # 有向グラフでは削除
e[x-1].append((1, y-1))
e[y-1].append((1, x-1))
d = [dijkstra(i) for i in range(n)]
d = [sorted(d[i][i:]) for i in range(n)]
import bisect
for i in range(1,n):
ans = 0
for j in range(n):
ans += bisect.bisect_right(d[j], i) - bisect.bisect_left(d[j], i)
print(ans)
|
n,x,y = list(map(int,input().split()))
import heapq
def dijkstra(s):
hq = [(0, s)]
heapq.heapify(hq) # リストを優先度付きキューに変換
cost = [float('inf')] * n # 行ったことのないところはinf
cost[s] = 0 # 開始地点は0
while hq:
c, v = heapq.heappop(hq)
if c > cost[v]: # コストが現在のコストよりも高ければスルー
continue
for d, u in e[v]:
tmp = d + cost[v]
if tmp < cost[u]:
cost[u] = tmp
heapq.heappush(hq, (tmp, u))
return cost
e = [[] for _ in range(n)]
for i in range(n-1):
e[i].append((1, i+1))
e[i+1].append((1, i)) # 有向グラフでは削除
e[x-1].append((1, y-1))
e[y-1].append((1, x-1))
d = [sorted(dijkstra(i)[i:]) for i in range(n)]
import bisect
for i in range(1,n):
ans = 0
for j in range(n):
ans += bisect.bisect_right(d[j], i) - bisect.bisect_left(d[j], i)
print(ans)
|
p02726
|
from collections import deque
class Node:
def __init__(self, idx):
self.idx = idx
self.a = []
n, x, y = list(map(int, input().split()))
nodes = []
for i in range(n):
node = Node(i+1)
nodes.append(node)
for i in range(n-1):
cur = nodes[i]
next = nodes[i+1]
cur.a.append(next)
next.a.append(cur)
X = nodes[x-1]
Y = nodes[y-1]
X.a.append(Y)
Y.a.append(X)
dp = [[None] * (n+1) for _ in range(n+1)]
for i in range(n):
node = nodes[i]
q = deque()
q.append((node, 0))
done = set()
while q:
t = q.popleft()
node, d = t[0], t[1]
if node.idx not in done:
dp[i + 1][node.idx] = d
done.add(node.idx)
for adj in node.a:
q.append((adj, d + 1))
# for i in range(1, n+1):
# print(dp[i])
for k in range(1, n):
temp = 0
for i in range(1, n+1):
for j in range(1, n+1):
if dp[i][j] == k:
temp += 1
print((temp//2))
|
from collections import deque
class Node:
def __init__(self, idx):
self.idx = idx
self.a = []
n, x, y = list(map(int, input().split()))
nodes = []
for i in range(n):
node = Node(i+1)
nodes.append(node)
for i in range(n-1):
cur = nodes[i]
next = nodes[i+1]
cur.a.append(next)
next.a.append(cur)
X = nodes[x-1]
Y = nodes[y-1]
X.a.append(Y)
Y.a.append(X)
dp = [[None] * (n+1) for _ in range(n+1)]
for i in range(n):
node = nodes[i]
q = deque()
q.append((node, 0))
done = set()
while q:
t = q.popleft()
node, d = t[0], t[1]
if node.idx not in done:
dp[i + 1][node.idx] = d
done.add(node.idx)
for adj in node.a:
q.append((adj, d + 1))
# for i in range(1, n+1):
# print(dp[i])
m = {}
for i in range(1, n + 1):
for j in range(1, n + 1):
dis = dp[i][j]
if dis in m:
m[dis] += 1
else:
m[dis] = 1
for k in range(1, n):
if k in m:
print((m[k] // 2))
else:
print((0))
|
p02726
|
import sys
from heapq import heapify, heappop, heappush
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def dijkstra(start):
INF = 10 ** 10
dist = [INF] * (N+1)
dist[start] = 0
que = [(0,start)]
while que:
d, prev = heappop(que)
if dist[prev] < d:
continue
for next in graph[prev]:
d1 = d + 1
if dist[next] > d1:
dist[next] = d1
heappush(que, (d1, next))
return dist
N, X, Y = lr()
answer = [0] * N # 1-indexed
graph = [[] for _ in range(N+1)] # 1-indexed
for i in range(1, N):
graph[i].append(i+1)
graph[i+1].append(i)
graph[X].append(Y)
graph[Y].append(X)
dist_X = dijkstra(X)
dist_Y = dijkstra(Y)
for i in range(1, N):
for j in range(i+1, N+1):
d = min(j-i, dist_X[i] + dist_X[j], dist_Y[i] + dist_Y[j])
answer[d] += 1
print(*answer[1:], sep='\n')
|
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, X, Y = lr()
dis = [[0] * (N+1) for _ in range(N+1)]
for i in range(1, N):
for j in range(i+1, N+1):
dis[i][j] = j - i
dis[j][i] = j - i
dis[X][Y] = 1
dis[Y][X] = 1
for i in range(1, N):
for j in range(i+1, N+1):
dis[i][j] = min(dis[i][j], dis[i][X] + 1 + dis[Y][j])
answer = [0] * (N)
for i in range(1, N):
for j in range(i+1, N+1):
d = dis[i][j]
answer[d] += 1
print(('\n'.join(map(str, answer[1:]))))
|
p02726
|
# -*- coding: utf-8 -*-
import collections
N,X,Y = list(map(int,input().split()))
ToltN=N*(N-1)/2
Dist=[[0 for i in range(N)] for i in range(N)]
for i in range(N):
for j in range(i,N):
MyDist=abs(i-(X-1))+abs(j-(Y-1))+1
if MyDist<j-i:
Dist[i][j]=MyDist
else:
Dist[i][j] = j-i
for j in range(N-1):
ans=[0]
for i in range(N):
ans+=Dist[i]
c = collections.Counter(ans)
for i in range(N-1):
print((c[i+1]))
|
# -*- coding: utf-8 -*-
import collections
N,X,Y = list(map(int,input().split()))
ToltN=N*(N-1)/2
Dist=[[0 for i in range(N)] for i in range(N)]
c=[0]*N
for i in range(N):
for j in range(i+1,N):
MyDist=abs(i-(X-1))+abs(j-(Y-1))+1
if MyDist<j-i:
Dist[i][j]=MyDist
c[MyDist-1]+=1
else:
Dist[i][j] = j-i
c[j-i-1]+=1
for i in range(N-1):
print((c[i]))
|
p02726
|
n, x, y = list(map(int, input().split()))
ans = dict.fromkeys(list(range(1, n)), 0)
for i in range(1, n+1):
for j in range(i+1, n+1):
d = min(abs(j - i), abs(x - i) + 1 + abs(y - j), abs(x - j) + 1 + abs(y - i))
ans[d] += 1
for v in list(ans.values()):
print(v)
|
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):
ans[min(abs(j - i), abs(x - i) + 1 + abs(y - j), abs(x - j) + 1 + abs(y - i))] += 1
for e in ans[1:]:
print(e)
|
p02726
|
from itertools import combinations
N,X,Y = list(map(int, input().split()))
ans = [0]*(N-1)
for a,b in combinations(list(range(N)),2):
c = min([abs(a-b), abs(X-1-a)+abs(Y-1-b)+1, abs(Y-1-a)+abs(X-1-b)+1])
ans[c-1] += 1
print(("\n".join([str(i) for i in ans])))
|
from itertools import combinations
N,X,Y = list(map(int, input().split()))
ans = [0]*(N-1)
for a,b in combinations(list(range(N)),2):
c = min([abs(a-b), abs(X-1-a)+abs(Y-1-b)+1, abs(Y-1-a)+abs(X-1-b)+1])
ans[c-1] += 1
for i in ans: print(i)
|
p02726
|
from collections import deque, Counter
INF = float("inf")
N, X, Y = list(map(int, input().split()))
E = [[] for _ in range(N + 1)]
for i in range(1, N):
E[i].append(i + 1)
E[i + 1].append(i)
E[X].append(Y)
E[Y].append(X)
C = Counter()
for s in range(1, N + 1):
dist = [INF] * (N + 1)
dist[s] = 0
Q = deque([s])
while Q:
p = Q.popleft()
for c in E[p]:
if dist[c] > dist[p] + 1:
dist[c] = dist[p] + 1
Q.append(c)
C.update(dist)
for k in range(1, N):
print((C[k] // 2))
|
from itertools import combinations
N, X, Y = list(map(int, input().split()))
A = [0] * N
for i, j in combinations(list(range(1, N + 1)), 2):
A[min(abs(i - j), abs(X - i) + abs(Y - j) + 1, abs(X - j) + abs(Y - i) + 1)] += 1
for a in A[1:]:
print(a)
|
p02726
|
n, x, y = list(map(int,input().split()))
cnt = 0
ans=[0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
d = min(j-i,abs(x-i)+abs(y-j)+1)
ans[d] += 1
for i in range(1,n):
print((ans[i]))
|
def main():
n, x, y = list(map(int,input().split()))
cnt = 0
ans=[0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
d = min(j-i,abs(x-i)+abs(y-j)+1)
ans[d] += 1
for i in range(1,n):
print((ans[i]))
if __name__ == "__main__":
main()
|
p02726
|
n, x, y = list(map(int, input().split()))
inf = 1000000000
edges = [[inf] * n for _ in range(n)]
for i in range(n - 1):
edges[i][i + 1] = 1
edges[i + 1][i] = 1
edges[x - 1][y - 1] = 1
for k in range(n):
for i in range(n):
for j in range(n):
edges[i][j] = min(edges[i][j], edges[i][k] + edges[k][j])
cnts = [0] * (n - 1)
for i in range(n - 1):
for j in range(i + 1, n):
cnts[edges[i][j] - 1] += 1
for x in cnts:
print(x)
|
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):
ans[min(j - i, min(abs(i - x) + 1 + abs(y - j),
abs(i - y) + 1 + abs(x - j)))] += 1
for x in ans[1:]:
print(x)
|
p02726
|
n,x,y=list(map(int,input().split()))
x-=1
y-=1
d=[10000 for i in range(n)]
ans=[0 for i in range(n)]
for i in range(n):
d[i]=0
for j in range(i,n):
if(i==j):continue
d[j]=min(abs(i-j),abs(x-i)+abs(y-j)+1,abs(y-i)+abs(x-j)+1)
for j in range(n):
ans[d[j]]+=1
for i in range(1,n):
print((ans[i]))
|
n,x,y=list(map(int,input().split()))
x-=1
y-=1
d=[10000 for i in range(n)]
ans=[0 for i in range(n)]
for i in range(n):
for j in range(i,n):
m=min(abs(i-j),abs(x-i)+abs(y-j)+1,abs(y-i)+abs(x-j)+1)
ans[m]+=1
for i in range(1,n):
print((ans[i]))
|
p02726
|
N,X,Y = list(map(int,input().split()))
ans = [0]*(N-1)
X , Y = X-1 , Y-1#配列の場所に合わせる
for i in range(N):
for k in range(N):
if i == k:
pass
else:
if i < k:
ans_ = min(abs(k-i),abs(X-i)+abs(Y-k)+1)
ans[ans_-1] += 1
else:
ans_ = min(abs(k-i),abs(X-k)+abs(Y-i)+1)
ans[ans_-1] += 1
ans = [int(i/2) for i in ans]
for i in ans:
print(i)
|
n,x,y=list(map(int,input().split()))
c=[0]*~-n
for i in range(n):
for j in range(i):
c[min(~j+i,abs(~j+x)+abs(~i+y))]+=1
for i in c:
print(i)
|
p02726
|
N,X,Y=list(map(int,input().split()))
L=[[i+1 for i in range(j+1)][::-1]+[0]*(N-1-j) for j in range(N-1)]
for i in range(len(L)):
L[i]=[0]+L[i]+[0]
L.append([0]*(N+2))
L.insert(0,[0]*(N+2))
L.insert(0,[0]*(N+2))
H=[i+1 for i in range(N-1)][::-1]
L[Y][X]=1
task=[(Y,X,1)]
while len(task)>0:
P=task.pop()
y,x,c=P[0],P[1],P[2]
if y<0 or x<0 or y>N or x>N:
continue
if L[y+1][x]>c+1:
L[y+1][x]=c+1
task.append((y+1,x,c+1))
if L[y-1][x]>c+1:
L[y-1][x]=c+1
task.append((y-1,x,c+1))
if L[y][x+1]>c+1:
L[y][x+1]=c+1
task.append((y,x+1,c+1))
if L[y][x-1]>c+1:
L[y][x-1]=c+1
task.append((y,x-1,c+1))
#print(y,x,c)
#print(numpy.array(L))
LL=[]
for i in range(len(L)):
LL+=L[i]
import collections
D=collections.Counter(LL)
d=list(D.values())
d.pop(0)
d+=[0]*(max(N-len(d)-1,0))
for i in d:
print(i)
|
N,X,Y=list(map(int,input().split()))
ans=[0]*N
X-=1
Y-=1
for i in range(N-1):
for j in range(i+1,N):
ans[min(j-i,abs(j-Y)+abs(i-X)+1)]+=1
ans.pop(0)
for i in ans:
print(i)
|
p02726
|
n, x, y = list(map(int, input().split()))
ans = [0] * n
a = [n] * n
x -= 1
y -= 1
for i in range(0, n):
a = [n] * n
a[i] = 0
for j in range(i, 0, -1):
if j == x:
a[y] = min(a[y], a[j] + 1)
if j == y:
a[x] = min(a[x], a[j] + 1)
a[j - 1] = min(a[j - 1], a[j] + 1)
for j in range(i, n - 1):
if j == x:
a[y] = min(a[y], a[j] + 1)
if j == y:
a[x] = min(a[x], a[j] + 1)
a[j + 1] = min(a[j + 1], a[j] + 1)
for j in range(x, 0, -1):
if j == x:
a[y] = min(a[y], a[j] + 1)
if j == y:
a[x] = min(a[x], a[j] + 1)
a[j - 1] = min(a[j - 1], a[j] + 1)
for j in range(x, n - 1):
if j == x:
a[y] = min(a[y], a[j] + 1)
if j == y:
a[x] = min(a[x], a[j] + 1)
a[j + 1] = min(a[j + 1], a[j] + 1)
for j in range(y, 0, -1):
if j == x:
a[y] = min(a[y], a[j] + 1)
if j == y:
a[x] = min(a[x], a[j] + 1)
a[j - 1] = min(a[j - 1], a[j] + 1)
for j in range(y, n - 1):
if j == x:
a[y] = min(a[y], a[j] + 1)
if j == y:
a[x] = min(a[x], a[j] + 1)
a[j + 1] = min(a[j + 1], a[j] + 1)
for k in range(0, n):
if k != i:
ans[a[k]] += 1
for i in range(1, n):
print((ans[i] // 2))
|
n, x, y = list(map(int, input().split()))
ans = [0] * n
a = [n] * n
x -= 1
y -= 1
for i in range(0, n):
a = [n] * n
a[i] = 0
b = [i, x, y, x, y]
for k in b:
for j in range(k, 0, -1):
if j == x:
a[y] = min(a[y], a[j] + 1)
if j == y:
a[x] = min(a[x], a[j] + 1)
a[j - 1] = min(a[j - 1], a[j] + 1)
for j in range(k, n - 1):
if j == x:
a[y] = min(a[y], a[j] + 1)
if j == y:
a[x] = min(a[x], a[j] + 1)
a[j + 1] = min(a[j + 1], a[j] + 1)
for k in range(0, n):
ans[a[k]] += 1
for i in range(1, n):
print((ans[i] // 2))
|
p02726
|
from itertools import combinations
N, X, Y = list(map(int, input().split()))
result = []
for i, j in combinations(list(range(1, N+1)), 2):
mins = min([j-i, abs(Y-j)+abs(X-i)+1])
result.append(mins)
print(N)
for i in range(1, N-1):
print((result.count(i+1)))
|
from itertools import combinations
N, X, Y = list(map(int, input().split()))
result = [0]*N
for i, j in combinations(list(range(1, N+1)), 2):
mins = min([j-i, abs(Y-j)+abs(X-i)+1])
result[mins] += 1
for i in range(1, N):
print((result[i]))
|
p02726
|
n,x,y = list(map(int,input().split()))
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
dis = [[float('inf')] * n for _ in range(n)]
ans = [0] * (n-1)
for i in range(n):
for j in range(n):
if abs(i - j) == 1:
dis[i][j] = 1
dis[x-1][y-1] = 1
dis[y-1][x-1] = 1
for i in range(n):
d = dijkstra(i, n, n, dis)
for j in d:
if j > 0:
ans[j-1] += 1
for i in ans:
print((i//2))
|
import heapq
def dijkstra(edges, s):
hq = []
d = [-1] * n
d[s] = 0
heapq.heappush(hq, (0, s))
while hq:
d1, p = heapq.heappop(hq)
for i in edges[p]:
if d[i] == -1 or d[i] > d1 + 1:
d[i] = d1 + 1
heapq.heappush(hq, (d1+1, i))
return d
n,x,y = list(map(int,input().split()))
edges = [[] for _ in range(n)]
for i in range(n):
if i == 0:
edges[i].append(i+1)
elif i == n-1:
edges[i].append(i-1)
else:
edges[i].append(i-1)
edges[i].append(i+1)
edges[x-1].append(y-1)
edges[y-1].append(x-1)
ans = [0] * (n-1)
for i in range(n):
d = dijkstra(edges, i)
for j in d:
if j != 0:
ans[j-1] += 1
for i in ans:
print((i//2))
|
p02726
|
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left #bisect_left(list, value)
import heapq
#from fractions import gcd
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print(('\n'.join(map(str, x))))
N, X, Y = list(map(int, input().split()))
def dijkstra_heap(s):
#始点sから各頂点への最短距離
d = [float("inf")] * N
used = [True] * N #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for e in edge[s]:
heapq.heappush(edgelist,e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,[e[0]+d[v],e[1]])
return d
# n,w = map(int,input().split()) #n:頂点数 w:辺の数
edge = [[] for i in range(N)]
for i in range(1, N-1):
edge[i].append([1, i+1])
edge[i].append([1, i-1])
edge[0].append([1, 1])
edge[N-1].append([1, N-2])
edge[X-1].append([1, Y-1])
edge[Y-1].append([1, X-1])
dd = defaultdict(int)
for i in range(N):
dists = dijkstra_heap(i)
for j in dists[i+1:]:
dd[j] += 1
for k in range(1, N):
print((dd[k]))
|
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left #bisect_left(list, value)
import heapq
#from fractions import gcd
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print(('\n'.join(map(str, x))))
N, X, Y = list(map(int, input().split()))
def dijkstra_heap(s,edge):
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,w = map(int,input().split()) #n:頂点数 w:辺の数
edge = [[] for i in range(N)]
for i in range(1, N-1):
edge[i].append([1, i+1])
edge[i].append([1, i-1])
edge[0].append([1, 1])
edge[N-1].append([1, N-2])
edge[X-1].append([1, Y-1])
edge[Y-1].append([1, X-1])
dd = defaultdict(int)
for i in range(N):
dists = dijkstra_heap(i, edge)
for j in dists[i+1:]:
dd[j] += 1
for k in range(1, N):
print((dd[k]))
|
p02726
|
#設定
import sys
input = sys.stdin.buffer.readline
#ライブラリインポート
from collections import defaultdict
import queue
INF = float("inf")
class Graph(object):
def __init__(self):
self.graph = defaultdict(list)
def __len__(self):
return len(self.graph)
def add_edge(self, a, b):
self.graph[a].append(b)
def get_nodes(self):
return list(self.graph.keys())
class BFS(object):
def __init__(self, graph, s, N):
self.g = graph.graph
self.Q = queue.Queue()
self.Q.put(s)
self.dist = [INF] * N
self.dist[s] = 0
self.visit = ["No"] * N
self.visit[s] = "Yes"
while not self.Q.empty():
v = self.Q.get()
for i in self.g[v]:
if self.visit[i] == "No":
self.dist[i] = self.dist[v] + 1
self.Q.put(i)
self.visit[i] = "Yes"
#入力受け取り
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
N, X, Y = getlist()
G = Graph()
G.add_edge(X - 1, Y - 1)
G.add_edge(Y - 1, X - 1)
for i in range(N - 1):
G.add_edge(i, i + 1)
G.add_edge(i + 1, i)
ans = [0] * N
for i in range(N):
BF = BFS(G, i, N)
dist = BF.dist
for j in range(N):
ans[dist[j]] += 1
# print(ans)
for i in range(1, N):
print((int(ans[i] // 2)))
if __name__ == '__main__':
main()
|
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
N, X, Y = getlist()
X -= 1; Y -= 1
D = defaultdict(int)
for i in range(N):
for j in range(i + 1, N):
var = min(j - i, abs(X - i) + abs(Y - j) + 1)
D[var] += 1
for i in range(1, N):
print((D[i]))
if __name__ == '__main__':
main()
|
p02726
|
#!/usr/bin/env python3
import sys
import collections
def solve(N: int, X: int, Y: int):
def len_shortest_path(i, j, X, Y):
return min(abs(j-i), abs(X-i) + abs(Y-j) + 1)
result = collections.defaultdict(int)
for i in range(1, N+1):
for j in range(i+1, N+1):
shortest_path = len_shortest_path(i, j, X, Y)
result[shortest_path] += 1
for i in range(1, N):
print((result[i]))
def solve_slow(N: int, X: int, Y: int):
d = [[100000000 for i in range(N)] for j in range(N)]
X -= 1
Y -= 1
for i in range(N):
d[i][i] = 0
if i < N-1:
d[i][i+1] = 1
d[i+1][i] = 1
d[X][Y] = 1
d[Y][X] = 1
for k in range(N):
for i in range(N):
for j in range(N):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
count_dict = collections.defaultdict(int)
for row in d:
for i in row:
count_dict[i] += 1
for i in range(1, N):
print((count_dict[i]))
return
def solve_slow(N: int, X: int, Y: int):
d = [[100000000 for i in range(N)] for j in range(N)]
X -= 1
Y -= 1
for i in range(N):
d[i][i] = 0
if i < N-1:
d[i][i+1] = 1
d[i+1][i] = 1
d[X][Y] = 1
d[Y][X] = 1
for k in range(N):
for i in range(N):
for j in range(N):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
count_dict = collections.defaultdict(int)
for row in d:
for i in row:
count_dict[i] += 1
for i in range(1, N):
print((count_dict[i]))
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
import collections
def solve(N: int, X: int, Y: int):
X = X - 1
Y = Y - 1
counter = collections.defaultdict(int)
for i in range(N):
for j in range(i+1, N):
k = min(j - i, abs(Y-j) + abs(X-i) + 1)
counter[k] += 1
for i in range(1, N):
print((counter[i]))
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
|
N, X, Y = list(map(int, input().split()))
neighbor = { i: [] for i in range(1, N+1) }
for i in range(1,N):
neighbor[i].append(i+1)
neighbor[N-i+1].append(N-i)
neighbor[X].append(Y)
neighbor[Y].append(X)
distanced_neighbor = { i: { j: [] for j in range(1, N)} for i in range(1, N+1) }
for i in range(1, N+1):
visited = [i]
next_nodes = neighbor[i]
for j in range(1, N):
distanced_neighbor[i][j] = next_nodes[:]
queue = next_nodes[:]
visited += next_nodes
next_nodes = []
for q in queue:
for node in neighbor[q]:
if node in visited:
continue
else:
next_nodes.append(node)
next_nodes = list(set(next_nodes))
for i in range(1, N):
print((sum([len(distanced_neighbor[j][i]) for j in range(1, N+1)])//2))
|
N, X, Y = list(map(int, input().split()))
for K in range(1,N):
res = 0
for i in range(N-1):
for j in range(i+1,N):
min_dist = min(abs(j-i), abs(X-1-i)+1+abs(Y-1-j), abs(Y-1-i)+1+abs(X-1-j))
if min_dist == K:
res += 1
print(res)
|
p02726
|
import sys
import os
import math
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N, X, Y = il()
ret = [0] * (N - 1)
X -= 1
Y -= 1
for i in range(N - 1):
for j in range(i + 1, N):
k = min(abs(i - j), abs(X - i) + abs(Y - j) + 1, abs(Y - i) + abs(X - j) + 1)
ret[k - 1] += 1
for r in ret:
print(r)
if __name__ == '__main__':
main()
|
import sys
import os
import math
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N, X, Y = il()
ret = [0] * (N - 1)
X -= 1
Y -= 1
for i in range(N - 1):
for j in range(i + 1, N):
k = min(abs(i - j), abs(X - i) + abs(Y - j) + 1, abs(Y - i) + abs(X - j) + 1)
ret[k - 1] += 1
print(*ret, sep="\n")
if __name__ == '__main__':
main()
|
p02726
|
from collections import Counter
N, X, Y = list(map(int, input().split()))
def dijkstra(s, n, w, cost):
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
cost = [[float("inf") for _ in range(N)] for _ 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
res = Counter()
for i in range(N):
res += Counter(dijkstra(i, N, N, cost)[:i])
for i in range(N-1):
print((res[i+1]))
|
from collections import Counter, defaultdict, deque
N, X, Y = list(map(int, input().split()))
d = defaultdict(set)
for i in range(N-1):
d[i].add(i+1)
d[i+1].add(i)
d[X-1].add(Y-1)
d[Y-1].add(X-1)
cost = [[N]*N for _ in range(N)]
q = deque()
for i in range(N):
q.append((i, 0))
cost[i][i] = 0
while q:
u, st = q.popleft()
for v in d[u]:
if v != u and cost[i][v] > st+1:
cost[i][v] = st+1
q.append((v, st+1))
res = Counter()
for i, c in enumerate(cost):
res += Counter(c[:i])
for i in range(N - 1):
print((res[i + 1]))
|
p02726
|
n, x, y = list(map(int, input().split()))
li = []
x -= 1
y -= 1
for i in range(n-1):
li_i = []
for j in range(i+1, n):
li_i.append(min(j-i, abs(x-i)+abs(y-j)+1))
li.append(li_i)
for i in range(1,n):
a = 0
for j in range(n-1):
for k in range(n-1-j):
if li[j][k] == i:
a += 1
print(a)
|
n, x, y = list(map(int, input().split()))
li = [0 for i in range(n-1)]
x -= 1
y -= 1
for i in range(n-1):
for j in range(i+1, n):
a = min(j-i, abs(x-i)+abs(y-j)+1)
li[a-1] += 1
for x in li:
print(x)
|
p02726
|
import heapq
INFTY = 10**4
N,X,Y = list(map(int,input().split()))
C = {k:0 for k in range(N)}
G = {i:[] for i in range(1,N+1)}
G[1].append(2)
G[N].append(N-1)
for i in range(2,N):
G[i].append(i-1)
G[i].append(i+1)
G[X].append(Y)
G[Y].append(X)
for i in range(1,N+1):
heap = [(0,i)]
dist = [INFTY for _ in range(N+1)]
dist[i] = 0
hist = [0 for _ in range(N+1)]
while heap:
d,x = heapq.heappop(heap)
if dist[x]<d:continue
hist[x]=1
for y in G[x]:
if hist[y]==0 and dist[y]>d+1:
dist[y] = d+1
heapq.heappush(heap,(dist[y],y))
for j in range(1,N+1):
C[dist[j]] += 1
for k in range(1,N):
print((C[k]//2))
|
import heapq
INFTY = 10**4
N,X,Y = list(map(int,input().split()))
G = {i:[] for i in range(1,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)
dist = [[INFTY for _ in range(N+1)] for _ in range(N+1)]
for i in range(N+1):
dist[i][i] = 0
for i in range(1,N+1):
hist = [0 for _ in range(N+1)]
heap = [(0,i)]
hist[i] = 1
while heap:
d,x = heapq.heappop(heap)
if d>dist[i][x]:continue
hist[x] = 1
for y in G[x]:
if hist[y]==0:
if dist[i][y]>d+1:
dist[i][y] = d+1
heapq.heappush(heap,(d+1,y))
C = {k:0 for k in range(1,N)}
for i in range(1,N):
for j in range(i+1,N+1):
C[dist[i][j]] += 1
for k in range(1,N):
print((C[k]))
|
p02726
|
# -*- coding: utf-8 -*-
import queue
n, x, y = map(int, input().split())
x -= 1
y -= 1
INF = 10010101010101
ans = [0]*n
def put(v, d):
if dist[v] != INF:
return
dist[v] = d
q.put(v)
for sv in range(n):
q = queue.Queue()
dist = [INF for _ in range(n)]
put(sv, 0)
while not q.empty():
v = q.get()
d = dist[v]
if v-1 >= 0:
put(v-1, d+1)
if v+1 < n:
put(v+1, d+1)
if v == x:
put(y, d+1)
if v == y:
put(x, d+1)
for i in range(n):
ans[dist[i]] += 1
for i in range(n):
ans[i] = int(ans[i] / 2)
print(*ans[1:], sep='\n')
|
# -*- coding: utf-8 -*-
n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = [0]*n
for i in range(n):
for j in range(i + 1, n):
dist1 = j - i
dist2 = abs(x - i) + abs(y - j) + 1
ans[min(dist1, dist2)] += 1
print(*ans[1:], sep='\n')
|
p02726
|
from collections import defaultdict, deque
def solve():
N, X, Y = list(map(int, input().split()))
cnter = [0] * N
for start in range(N-1):
deq = deque()
deq.append(start)
n_step = [float('inf')] * N
n_step[start] = 0
visited = [False] * N
while len(deq) > 0:
fr = deq.popleft()
visited[fr] = True
if fr == X-1:
if not visited[Y-1] or n_step[Y-1] > n_step[X-1]+1:
n_step[Y-1] = n_step[X-1]+1
deq.append(Y-1)
visited[Y-1] = True
if fr == Y-1:
if not visited[X-1] or n_step[X-1] > n_step[Y-1]+1:
n_step[X-1] = n_step[Y-1]+1
deq.append(X-1)
visited[X-1] = True
if fr != N-1:
if not visited[fr+1] or n_step[fr+1] > n_step[fr]+1:
deq.append(fr+1)
n_step[fr+1] = n_step[fr]+1
visited[fr+1] = True
if fr != 0:
if not visited[fr-1] or n_step[fr-1] > n_step[fr]+1:
deq.append(fr-1)
n_step[fr-1] = n_step[fr]+1
visited[fr-1] = True
for i in range(start,N):
cnter[n_step[i]] += 1
for i in range(1,N):
print((cnter[i]))
if __name__ == '__main__':
solve()
|
from collections import defaultdict, deque
def solve():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
cnter = defaultdict(int)
for i in range(N):
for j in range(i,N):
n_step = min(abs(j-i), abs(X-i)+1+abs(Y-j), abs(Y-i)+1+abs(j-X))
cnter[n_step] += 1
for i in range(1,N):
print((cnter[i]))
if __name__ == '__main__':
solve()
|
p02726
|
import math
from math import gcd,pi,sqrt
INF = float("inf")
import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(eval(input()))
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return eval(input())
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def main():
n, x, y = i_map()
p = [[INF]*n for i in range(n)]
for i in range(n-1):
p[i][i] = 0
p[i][i+1] = p[i+1][i] = 1
p[-1][-1] = 0
x -= 1
y -= 1
p[x][y] = p[y][x] = 1
for k in range(n):
for i in range(n):
for j in range(n):
p[i][j] = min(p[i][j], p[i][k] + p[k][j])
p = list(itertools.chain.from_iterable(p))
p.sort()
p = [i for i in p if i != 0]
start = 1
cnt = 0
for i in p:
if start != i:
start = i
print((cnt//2))
cnt = 1
else:
cnt += 1
print((cnt//2))
for i in range(n-start-1):
print((0))
if __name__=="__main__":
main()
|
import math
from math import gcd,pi,sqrt
INF = float("inf")
import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def main():
n, x, y = i_map()
ans = [0] * n
for fr in range(1, n+1):
for to in range(fr+1, n+1):
cost = min(to - fr, abs(x-fr) + abs(to - y) + 1)
ans[cost] += 1
print(*ans[1:], sep="\n")
if __name__=="__main__":
main()
|
p02726
|
from collections import deque, defaultdict
n, x, y = list(map(int, input().split()))
edges = defaultdict(lambda: [])
for i in range(1, n):
edges[i].append(i+1)
edges[i+1].append(i)
edges[x].append(y)
edges[y].append(x)
# 幅優先
counter = [0 for i in range(n)]
for i in range(1, n+1):
d = deque()
is_checked = [False for _ in range(n+1)]
dist = [-1 for _ in range(n+1)]
dist[i] = 0
d.append((i, 0))
while len(d) > 0:
e, pre_dist = d.popleft()
if is_checked[e]:
continue
else:
is_checked[e] = True
dist[e] = pre_dist + 1
for next_e in edges[e]:
if not is_checked[next_e]:
d.append((next_e, pre_dist+1))
for j in range(i+1, n+1):
counter[dist[j]-1] += 1
print(("\n".join(list(map(str, counter[1:])))))
|
from collections import deque, defaultdict
n, x, y = list(map(int, input().split()))
edges = defaultdict(lambda: [])
for i in range(1, n):
edges[i].append(i+1)
edges[i+1].append(i)
edges[x].append(y)
edges[y].append(x)
# 幅優先
counter = [0 for i in range(n)]
for i in range(1, n+1):
d = deque()
dist = [-1 for _ in range(n+1)]
d.append((i, -1))
while len(d) > 0:
e, pre_dist = d.popleft()
if dist[e] > -1:
continue
else:
dist[e] = pre_dist + 1
for next_e in edges[e]:
if dist[next_e] == -1:
d.append((next_e, pre_dist+1))
for j in range(i+1, n+1):
counter[dist[j]] += 1
print(("\n".join(list(map(str, counter[1:])))))
|
p02726
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
D = [0] * N
for i in range(N):
for j in range(i, N):
m = min(abs(j - i), abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X))
D[m] += 1
for v in D[1:N]:
print(v)
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
D = [0] * N
for i in range(N):
for j in range(i + 1, N):
m = min(abs(j - i), abs(i - X) + 1 + abs(j - Y))
D[m] += 1
for v in D[1:N]:
print(v)
|
p02726
|
from collections import defaultdict
import heapq
def dijkstra(n, s, edges, count):
dist = [float('inf') for _ in range(n)]
dist[s] = 0
q = []
heapq.heappush(q, (0, s))
while len(q):
d, p = heapq.heappop(q)
if s < p:
count[d] += 1
if dist[p] < d:
continue
for e in edges[p]:
if d + 1 < dist[e]:
dist[e] = d + 1
heapq.heappush(q, (dist[e], e))
return dist, count
def submit():
n, x, y = list(map(int, input().split()))
edges = {i: [] for i 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)
dist_list = {}
count = defaultdict(int)
for s in range(n):
dist_list[s], count = dijkstra(n, s, edges, count)
for i in range(1, n):
print((count[i]))
submit()
|
def submit():
n, x, y = list(map(int, input().split()))
count = {i: 0 for i in range(1, n)}
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
# i, j <= X, or Y <= i, j
if (i <= x and j <= x) or (x <= i and y <= j):
d = j - i
# X < i, j < Y
if x < i and j < y:
d = min(j - i, i - x + 1 + y - j)
# i <= X and X < j < Y
if i <= x and x < j < y:
d = min(j - i,
x - i + 1 + y - j)
# X < i < Y and Y <= j
if x < i < y and y <= j:
d = min(j - i,
j - y + 1 + i - x)
if i <= x and y <= j:
d = min(j - i,
x - i + j - y + 1)
count[d] += 1
for i in range(1, n):
print((count[i]))
submit()
|
p02726
|
from sys import stdin
from collections import deque
def get_adj_list(num_nodes, data, undirected=True):
# adj_list ex) {1:[2,3,4], 2:[1,4,5], 3:[1,4], 4:[1,2,3,5], 5:[2,4]}
graph = {}
for i in range(num_nodes):
graph[i+1] = []
for val in data:
x, y = val
graph[x] = graph[x] + [y]
if undirected:
graph[y] = graph[y] + [x]
return graph
def breadth_first_search(adj_list, start_node):
dist = {}
queue = deque([(start_node, 0)])
while len(queue) > 0:
v, d = queue.popleft()
if v in dist: continue
dist[v] = d
for u in adj_list[v]:
if u not in dist:
queue.append((u, d+1))
return dist
# bfs
def get_result(data):
N, X, Y = data
_data = [[i, i+1] for i in range(1, N)]
_data += [[X, Y]]
adj_list = get_adj_list(N, _data)
dist_cnt = [0 for i in range(N)]
for i in range(N):
dist = breadth_first_search(adj_list, i+1)
for j in range(i, N):
dist_cnt[dist[j+1]] += 1
for i in range(1, N):
print((dist_cnt[i]))
# 解説のコード
# def get_result(data):
# N, X, Y = data
# dist_cnt = [0 for i in range(N)]
# for i in range(1, N+1):
# for j in range(i+1, N+1):
# min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)])
# dist_cnt[min_dist] += 1
# for i in range(1, N):
# print(dist_cnt[i])
if __name__ == '__main__':
data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
get_result(data)
|
# from sys import stdin
# # 解説のコード
# def get_result(data):
# N, X, Y = data
# dist_cnt = [0 for i in range(N)]
# for i in range(1, N+1):
# for j in range(i+1, N+1):
# min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)])
# dist_cnt[min_dist] += 1
# for i in range(1, N):
# print(dist_cnt[i])
# if __name__ == '__main__':
# data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
# get_result(data)
from sys import stdin
from collections import deque
# 重みなしグラフの隣接リスト
# 0-indexed nodes
def get_adj_list(num_nodes, data, undirected=True):
graph = [[] for _ in range(num_nodes)]
for val in data:
x, y = val
graph[x-1] = graph[x-1] + [y-1]
if undirected:
graph[y-1] = graph[y-1] + [x-1]
return graph
# BFS
def breadth_first_search(adj_list, start_node):
N = len(adj_list)
order = [-1] * N # a bfs ordering of each vertex
parent = [-1] * N # parent of each vertex in the bfs search tree
depth = [-1] * N # the depth of each vertex
q = deque([(start_node, -1, 0)]) # (vertex, parent, depth)
num = 0 # current ordering
while q:
v, p, d = q.popleft()
if order[v] < 0: # visited v for the first time
order[v] = num
parent[v] = p
depth[v] = d
num += 1
for u in adj_list[v]:
if order[u] >= 0: continue
q.append((u, v, d+1))
return order, parent, depth
# BFS pypyでAC
def get_result(data):
N, X, Y = data
_data = [[i, i+1] for i in range(1, N)]
_data += [[X, Y]]
adj_list = get_adj_list(N, _data)
dist_cnt = [0 for i in range(N)]
for i in range(N):
_, _, depth = breadth_first_search(adj_list, i)
for j in range(i, N):
dist_cnt[depth[j]] += 1
for i in range(1, N):
print((dist_cnt[i]))
if __name__ == '__main__':
data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
get_result(data)
|
p02726
|
# from sys import stdin
# # 解説のコード
# def get_result(data):
# N, X, Y = data
# dist_cnt = [0 for i in range(N)]
# for i in range(1, N+1):
# for j in range(i+1, N+1):
# min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)])
# dist_cnt[min_dist] += 1
# for i in range(1, N):
# print(dist_cnt[i])
# if __name__ == '__main__':
# data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
# get_result(data)
from sys import stdin
from collections import deque
# 重みなしグラフの隣接リスト
# 0-indexed nodes
def get_adj_list(num_nodes, data, undirected=True):
graph = [[] for _ in range(num_nodes)]
for val in data:
x, y = val
graph[x-1] = graph[x-1] + [y-1]
if undirected:
graph[y-1] = graph[y-1] + [x-1]
return graph
# BFS
def breadth_first_search(adj_list, start_node):
N = len(adj_list)
order = [-1] * N # a bfs ordering of each vertex
parent = [-1] * N # parent of each vertex in the bfs search tree
depth = [-1] * N # the depth of each vertex
q = deque([(start_node, -1, 0)]) # (vertex, parent, depth)
num = 0 # current ordering
while q:
v, p, d = q.popleft()
if order[v] < 0: # visited v for the first time
order[v] = num
parent[v] = p
depth[v] = d
num += 1
for u in adj_list[v]:
if order[u] >= 0: continue
q.append((u, v, d+1))
return order, parent, depth
# BFS pypyでAC
def get_result(data):
N, X, Y = data
_data = [[i, i+1] for i in range(1, N)]
_data += [[X, Y]]
adj_list = get_adj_list(N, _data)
dist_cnt = [0 for i in range(N)]
for i in range(N):
_, _, depth = breadth_first_search(adj_list, i)
for j in range(i, N):
dist_cnt[depth[j]] += 1
for i in range(1, N):
print((dist_cnt[i]))
if __name__ == '__main__':
data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
get_result(data)
|
from sys import stdin
from collections import deque
# 重みなしグラフの隣接リスト
# 0-indexed nodes
def get_adj_list(num_nodes, data, undirected=True):
graph = [[] for _ in range(num_nodes)]
for val in data:
x, y = val
graph[x-1].append(y-1)
if undirected:
graph[y-1].append(x-1)
return graph
# BFS
def breadth_first_search(adj_list, start_node):
N = len(adj_list)
order = [-1] * N # a bfs ordering of each vertex
parent = [-1] * N # parent of each vertex in the bfs search tree
depth = [-1] * N # the depth of each vertex
q = deque([(start_node, -1, 0)]) # (vertex, parent, depth)
num = 0 # current ordering
while len(q) > 0:
v, p, d = q.popleft()
if order[v] < 0: # visited v for the first time
order[v] = num; parent[v] = p; depth[v] = d
num += 1
for u in adj_list[v]:
if order[u] >= 0: continue
q.append((u, v, d+1))
return order, parent, depth
# BFS pypyでAC
def get_result(data):
N, X, Y = data
_data = [[i, i+1] for i in range(1, N)]
_data += [[X, Y]]
adj_list = get_adj_list(N, _data)
dist_cnt = [0 for i in range(N)]
for i in range(N):
_, _, depth = breadth_first_search(adj_list, i)
for j in range(i, N):
dist_cnt[depth[j]] += 1
for i in range(1, N):
print((dist_cnt[i]))
if __name__ == '__main__':
data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
get_result(data)
|
p02726
|
from sys import stdin
from heapq import heappush, heappop
class Dijkstra:
def __init__(self, num_nodes):
self.n = num_nodes
# 隣接行列 d[u][v]: uからvへのコスト
self.adj_matrix = [[float("inf")]*self.n for i in range(self.n)]
# Edge数分回すことを想定
def add_edge(self, start, end, weight=1, undirected=False):
self.adj_matrix[start][end] = weight
if undirected:
self.adj_matrix[end][start] = weight
def distance(self, start):
# 始点から各頂点までの最短距離を格納する
self.dist = [float('inf') for _ in range(self.n)]
# 最短経路における, その頂点の前の頂点のIDを格納する
self.prev = [float('inf') for _ in range(self.n)]
self.dist[start] = 0
# 各要素は,(頂点vのID, startからある頂点vまでの仮の距離)からなるタプル
q = []
heappush(q, (start, 0))
while len(q) != 0:
src, prov_cost = heappop(q)
# プライオリティキューに格納されている最短距離が, 現在計算できている最短距離より大きければ,distの更新をする必要はない
if self.dist[src] < prov_cost:
continue
# 他の頂点の探索
for dest in range(self.n):
cost = self.adj_matrix[src][dest]
if cost != float('inf') and self.dist[dest] > self.dist[src] + cost:
self.dist[dest] = self.dist[src] + cost # distの更新
heappush(q, (dest, self.dist[dest])) # キューに新たな仮の距離の情報をpush
self.prev[dest] = src
return self.dist
def shortest_path(self, goal):
path = [goal]
dest = goal
# 終点から最短経路を逆順に辿る
while self.prev[dest] != float('inf'):
path.append(self.prev[dest])
dest = self.prev[dest]
return path[::-1]
# BFS pypyでAC
def get_result(data):
N, X, Y = data
_data = [[i, i+1] for i in range(1, N)]
_data += [[X, Y]]
solver = Dijkstra(N)
for val in _data:
solver.add_edge(val[0]-1, val[1]-1, undirected=True)
dist_cnt = [0 for i in range(N)]
for i in range(N):
dist = solver.distance(i)
for j in range(i, N):
dist_cnt[dist[j]] += 1
for i in range(1, N):
print((dist_cnt[i]))
if __name__ == '__main__':
data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
get_result(data)
|
# from sys import stdin
# # 解説のコード
# def get_result(data):
# N, X, Y = data
# dist_cnt = [0 for i in range(N)]
# for i in range(1, N+1):
# for j in range(i+1, N+1):
# min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)])
# dist_cnt[min_dist] += 1
# for i in range(1, N):
# print(dist_cnt[i])
# if __name__ == '__main__':
# data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
# get_result(data)
from sys import stdin
from heapq import heappush, heappop
class Dijkstra:
def __init__(self, num_nodes):
self.n = num_nodes
self.adj_list = [[] for _ in range(self.n)]
# Edge数分回すことを想定
def add_edge(self, start, end, weight=1, undirected=True):
self.adj_list[start].append((end, weight))
if undirected:
self.adj_list[end].append((start, weight))
def distance(self, start):
# 始点から各頂点までの最短距離を格納する
self.dist = [float('inf') for _ in range(self.n)]
# 最短経路における, その頂点の前の頂点のIDを格納する
self.prev = [-1 for _ in range(self.n)]
self.dist[start] = 0
# 各要素は,(頂点vのID, startからある頂点vまでの仮の距離)からなるタプル
q = []
heappush(q, (start, 0))
while len(q) != 0:
src, prov_cost = heappop(q)
# プライオリティキューに格納されている最短距離が, 現在計算できている最短距離より大きければ,distの更新をする必要はない
if self.dist[src] < prov_cost:
continue
# 他の頂点の探索
for val in self.adj_list[src]:
dest, cost = val
if self.dist[dest] > self.dist[src] + cost:
self.dist[dest] = self.dist[src] + cost # distの更新
heappush(q, (dest, self.dist[dest])) # キューに新たな仮の距離の情報をpush
self.prev[dest] = src
return self.dist
# BFS pypyでAC
def get_result(data):
N, X, Y = data
_data = [[i, i+1] for i in range(1, N)]
_data += [[X, Y]]
solver = Dijkstra(N)
for val in _data:
solver.add_edge(val[0]-1, val[1]-1, undirected=True)
dist_cnt = [0 for i in range(N)]
for i in range(N):
dist = solver.distance(i)
for j in range(i, N):
dist_cnt[dist[j]] += 1
for i in range(1, N):
print((dist_cnt[i]))
if __name__ == '__main__':
data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
get_result(data)
|
p02726
|
N, X, Y = list(map(int, input().split()))
l = []
for i in range(1, N):
for j in range(i+1, N+1):
s = j -i
if 0 < i < Y:
ss = abs(j - Y) + abs(X - i) + 1
l.append(min(s, ss))
elif i >= Y:
l.append(s)
for i in range(1, N):
print((l.count(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):
s = j -i
if 0 < i < Y:
ss = abs(j - Y) + abs(X - i) + 1
l[min(s, ss)-1] += 1
elif i >= Y:
l[s-1] += 1
for i in range(N-1):
print((l[i]))
|
p02726
|
n,x,y=list(map(int, input().split()))
dist=[]
for i in range(1,n+1):
for j in range(i+1,n+1):
dist.append(min(j-i,abs(j-y)+1+abs(i-x)))
for i in range(1,n):
print((dist.count(i)))
|
n,x,y=list(map(int, input().split()))
dist=[0]*(n+1)
for i in range(1,n+1):
for j in range(i+1,n+1):
dist[min(j-i,abs(j-y)+1+abs(i-x))]+=1
for i in range(1,n):
print((dist[i]))
|
p02726
|
from collections import deque
n,x,y = list(map(int,input().split()))
x,y = x-1 ,y-1
g = [[float('inf')]*n for _ in range(n)]
for i in range(n):
que = deque([(i, 0)])
while que:
node, cost = que.popleft()
if g[i][node]!=float('inf'):
continue
else:
g[i][node] = cost
if node>0:
que.append((node-1, cost+1))
if node<n-1:
que.append((node+1, cost+1))
if node==x:
que.append((y, cost+1))
if node==y:
que.append((x, cost+1))
cnt = [0]*n
for i in range(n):
for j in range(i+1, n):
cnt[g[i][j]] += 1
for c in cnt[1:]:
print(c)
|
from collections import deque
def main():
n,x,y = list(map(int,input().split()))
cnt = [0]*n
for i in range(n):
d = [float('inf')]*n
que = deque([(i, 0)])
while que:
idx, c = que.popleft()
if d[idx]!=float('inf'):
d[idx] = min(d[idx], c)
continue
else:
d[idx] = min(d[idx], c)
if idx!=0:
que.append((idx-1, c+1))
if idx!=n-1:
que.append((idx+1, c+1))
if idx==x-1:
que.append((y-1, c+1))
if idx==y-1:
que.append((x-1, c+1))
for j in range(i+1, n):
cnt[d[j]] += 1
for c in cnt[1:]:
print(c)
if __name__ == '__main__':
main()
|
p02726
|
def wf(d):
N = len(d)
for k in range(N):
for j in range(N):
for i in range(N):
d[j][i] = min(d[j][i], d[j][k] + d[k][i])
return d
N, x, y = list(map(int, input().split()))
x -= 1
y -= 1
d = [[float('inf') for _ in range(N)] for _ in range(N)]
for i in range(N-1):
d[i][i + 1] = 1
d[i + 1][i] = 1
d[x][y] = 1
d[y][x] = 1
for n in range(N):
d[n][n] = 0
d = wf(d)
cnt = {n: 0 for n in range(N)}
for i in range(N):
for j in range(i, N):
cnt[d[i][j]] += 1
for i in range(1, N):
print((cnt[i]))
|
N, x, y = list(map(int, input().split()))
cnt = {n: 0 for n in range(1, N)}
for i in range(1, N + 1):
for j in range(i+1, N + 1):
d1 = abs(i - j)
d2 = 1 + min(abs(x - i) + abs(y - j), abs(x - j) + abs(y - i))
cnt[min(d1, d2)] += 1
for k in range(1, N):
print((cnt[k]))
|
p02726
|
from collections import deque
import sys
input = sys.stdin.readline
n,x,y = list(map(int,input().split()))
to = [[] for _ in range(n)]
for i in range(n-1):
to[i].append(i+1)
to[i+1].append(i)
x -= 1
y -= 1
to[x].append(y)
to[y].append(x)
ans = [0]*(n-1)
d = {}
Q = deque()
flag = [False]*n
for i in range(n-1):
Q.clear()
Q.append((i,-1,0))
for j in range(n): flag[j] = False
flag[i] = True
while Q:
cur,prev,dist = Q.popleft()
for nxt in to[cur]:
if nxt == prev: continue
if flag[nxt]: continue
flag[nxt] = True
if (i,nxt) not in d: ans[dist] += 1
Q.append((nxt,cur,dist+1))
d[(i,nxt)] = 1
d[(nxt,i)] = 1
for i in range(n-1): print((ans[i]))
|
n,x,y = list(map(int,input().split()))
ans = [0]*(n-1)
x -= 1
y -= 1
for i in range(n-1):
for j in range(i+1,n):
dist = min(j-i,abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x))
ans[dist-1] += 1
print(("\n".join(map(str,ans))))
|
p02726
|
N, X, Y = map(int, input().split())
ans = [0]*N
for i in range(1,N+1):
for j in range(i+1,N+1):
d = min(j-i,abs(i-X)+abs(j-Y)+1)
#print(i,j,d)
ans[d]+=1
print(*ans[1:], sep='\n')
|
def solve():
N, X, Y = map(int, input().split())
ans = [0]*(N)
for i in range(1,N):
for j in range(i+1,N+1):
ans[min(abs(X-i)+abs(Y-j)+1,abs(j-i))] += 1
return ans[1:]
print(*solve(),sep='\n')
|
p02726
|
N,X,Y = list(map(int,input().split()))
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)
from collections import deque
def bfs(u):
queue = deque([u])
d = [None]*(N+1)
d[u]=0
while queue:
v = queue.popleft()
for i in g[v]:
if d[i] is None:
d[i]=d[v]+1
queue.append(i)
return d
ans = [0]*(N-1)
for i in range(1,N+1):
d = bfs(i)
for j in range(1,N+1):
if d[j]>0:
ans[d[j]-1] += 1
for a in ans:
print((a//2))
|
N,X,Y = list(map(int,input().split()))
g = [[] for _ in range(N+1)]
for i in range(1,N+1):
if i != 1:
g[i].append(i-1)
if i != N:
g[i].append(i+1)
g[X].append(Y)
g[Y].append(X)
from collections import deque
answer = [0]*(N+1)
for i in range(1,N+1):
q = deque([i])
d = [None]*(N+1)
d[i] = 0
while q:
p = q.popleft()
for j in g[p]:
if d[j] == None:
d[j] = d[p]+1
q.append(j)
for k in d[1:]:
answer[k] += 1
for l in answer[1:-1]:
print((l//2))
|
p02726
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans = [0] * n
for j in range(n):
for i in range(j):
d = min(j-i, abs(x-i)+1+abs(j-y))
ans[d] += 1
print(( "\n".join( [str(d) for d in ans[1:]] )))
|
n,x,y = list(map(int, input().split()))
x -= 1
y -= 1
ans = [0] * (n-1)
for j in range(n):
for i in range(j):
ans[min(j-i, abs(x-i)+1+abs(j-y)) - 1] += 1
print(("\n".join([str(d) for d in ans])))
|
p02726
|
n, x, y = list(map(int,input().split()))
x, y = x-1, y-1
d=[0 for i in range(n)]
for i in range(n):
for j in range(n):
m = min(abs(i-j), abs(x-i)+abs(y-j)+1, abs(x-j)+abs(y-i)+1)
d[m] += 1
for i in range(n-1):
print((d[i+1]//2))
|
n, x, y = list(map(int,input().split()))
x, y = x-1, y-1
d=[0 for i in range(n)]
for i in range(n):
for j in range(i+1,n):
m = min(abs(i-j), abs(x-i)+abs(y-j)+1, abs(x-j)+abs(y-i)+1)
d[m] += 1
for i in range(n-1):
print((d[i+1]))
|
p02726
|
n,x,y=list(map(int,input().split()))
a=[0]*n
z=y-x-1
for i in range(1,n):
for j in range(i+1,n+1):
p=min(j-i,abs(i-x)+1+abs(j-y))
a[p]+=1
for k in a[1:]:
print(k)
|
n,x,y=list(map(int,input().split()))
a=[0]*n
for i in range(1,n):
for j in range(i+1,n+1):
a[min(j-i,abs(i-x)+1+abs(j-y))]+=1
for k in a[1:]:
print(k)
|
p02726
|
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]))
|
N, X, Y = list(map(int,input().split()))
X -= 1
Y -= 1
out = [0]*N #最低距離が1から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
|
INF = float('inf')
from heapq import *
from collections import defaultdict
N,X,Y = list(map(int,input().split()))
X -= 1
Y -= 1
cost_pri = defaultdict(list)
for i in range(N-1):
cost_pri[i].append((i+1,1))
cost_pri[i+1].append((i,1))
cost_pri[X].append((Y,1))
cost_pri[Y].append((X,1))
ans = [0]*(N-1)
for s in range(N):
dist = [2**60]*N
dist[s] = 0
que = [[0,s]]
heapify(que)
while que:
p = heappop(que)
v = p[1]
if dist[v] < p[0]:continue
for e in cost_pri[v]:
if dist[e[0]] > dist[v] + e[1]:
dist[e[0]] = dist[v] + e[1]
heappush(que,[dist[e[0]],e[0]])
for a in dist[s+1:]:
ans[a-1] += 1
for a in ans:
print(a)
|
from heapq import *
from collections import defaultdict
N,X,Y = list(map(int,input().split()))
X -= 1
Y -= 1
cost_pri = defaultdict(list)
for i in range(N-1):
cost_pri[i].append((i+1,1))
cost_pri[i+1].append((i,1))
cost_pri[X].append((Y,1))
cost_pri[Y].append((X,1))
ans = [0]*(N-1)
for s in range(N):
dist = [2**60]*N
dist[s] = 0
que = [(0,s)]
heapify(que)
while que:
p = heappop(que)
v = p[1]
if dist[v] < p[0]:continue
for e in cost_pri[v]:
if dist[e[0]] > dist[v] + e[1]:
dist[e[0]] = dist[v] + e[1]
heappush(que,(dist[e[0]],e[0]))
for a in dist[s+1:]:
ans[a-1] += 1
for a in ans:
print(a)
|
p02726
|
from queue import Queue
def bfs(target, graph, ans):
visited = [False]*len(graph)
que = Queue()
que.put(target)
visited[target] = True
distance = [0]*len(graph)
while not que.empty():
root = que.get()
for dst in graph[root]:
if visited[dst] is False:
visited[dst] = True
que.put(dst)
dist = distance[root] + 1
distance[dst] = dist
ans[dist-1] += 1
n, x, y = list(map(int, input().split()))
graph = {i:[] for i in range(n)}
for i in range(n-1):
graph[i].append(i+1)
graph[i+1].append(i)
graph[x-1].append(y-1)
graph[y-1].append(x-1)
ans = [0]*(n-1)
for target in range(n):
bfs(target, graph, ans)
for a in ans:
print((a//2))
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
dist = [0]*(n-1)
for start in range(n):
for end in range(start+1, n):
dst = min(end-start, abs(x-start) + abs(end-y) + 1)
dist[dst-1] += 1
for d in dist:
print(d)
|
p02726
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
k = [0 for _ in range(n)]
for i in range(n):
for j in range(i + 1, n):
dist = min([j-i, abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x)])
if dist < n:
k[dist] += 1
for i in range(1, len(k)):
print((k[i]))
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
k = [0 for _ in range(n)]
for i in range(n):
for j in range(i + 1, n):
dist = min(j-i, abs(x-i)+1+abs(j-y))
if dist < n:
k[dist] += 1
for i in range(1, len(k)):
print((k[i]))
|
p02726
|
"""
"""
n,x,y=list(map(int,input().split()))
k_mins=[]
for i in range(1,n):
for j in range(i+1,n+1):
k_mins.append(min(j-i,abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i)))
ret=[]
k_mins.sort(reverse=True)
for i in range(1,n):
c=0
while len(k_mins) > 0 and k_mins[len(k_mins)-1]==i:
k_mins.pop()
c+=1
ret.append(c)
for r in ret:
print(r)
|
"""
"""
n,x,y=list(map(int,input().split()))
ret=[0]*(n-1)
for i in range(1,n):
for j in range(i+1,n+1):
ret[min(j-i,abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))-1]+=1
for r in ret:
print(r)
|
p02726
|
from collections import deque
n,x,y = [int(x) for x in input().split()]
l = [[] for i in range(n+1)]
p = []
q = []
l[1].append(2)
for i in range(2,n):
l[i].append(i+1)
l[i].append(i-1)
l[n].append(n-1)
l[x].append(y)
l[y].append(x)
clist = [0]*(n+1)
#ここまでで、グラフが隣接リスト表記で表される
for k in range(1,n+1):
d = deque()
dist = [-1]*(n+1)
dist[k] = 0
d.append(k)
while True:
v = d.popleft()
for i in l[v]:
if dist[i] != -1:
continue
dist[i] = dist[v] + 1
d.append(i)
if not d:
break
for j in dist[k+1:]:
clist[j] += 1
for i in range(1,n):
print((clist[i]))
|
n,x,y = [int(x) for x in input().split()]
count = [0]*(n+1)
for i in range(1,n):
for j in range(i+1,n+1):
if i < x and j <= x:
nagasa = j - i
elif i < x and x < j and j < y:
nagasa = x-i + min(j-x,y-j+1)
elif i < x and y <= j:
nagasa = x-i + j - y + 1
elif x <= i and i < y and j <= y:
nagasa = min(j-i,i-x+y-j+1)
elif x <= i and i < y and y < j:
nagasa = j - y + min(y-i,i-x+1)
elif y <= i:
nagasa = j -i
count[nagasa] += 1
for i in range(1,n):
print((count[i]))
|
p02726
|
from collections import deque, defaultdict
N, X, Y = list(map(int, input().split()))
# 全探索でいけるのでは?
# 有向グラフとしてN回幅優先すれば良いのでは?
tree = [[] for _ in range(N)]
for i in range(N-1):
tree[i].append(i+1)
tree[i+1].append(i)
tree[X-1].append(Y-1)
tree[Y-1].append(X-1)
ans = defaultdict(int)
q = deque()
# 更新されない時はqに追加しない
for i in range(N):
distant = [N]*N
q.append(i) # 始まりのノード
distant[i] = 0
while len(q):
# vは数字, 親のノードのインデックス
v = q.pop()
for e in tree[v]:
if distant[e] < distant[v]+1: # 到達済みなら次のノードへ
continue
distant[e] = min(distant[v]+1, distant[e])
q.append(e)
for d in distant:
ans[d] += 1
for i in range(1, N):
print((ans[i]//2))
|
from collections import deque, defaultdict
N, X, Y = list(map(int, input().split()))
# 全探索でいけるのでは?
# 有向グラフとしてN回幅優先すれば良いのでは?
tree = [[] for _ in range(N)]
for i in range(N-1):
tree[i].append(i+1)
tree[i+1].append(i)
tree[X-1].append(Y-1)
tree[Y-1].append(X-1)
ans = defaultdict(int)
q = deque()
# 更新されない時はqに追加しない
for i in range(N):
distant = [N]*N
q.append(i) # 始まりのノード
distant[i] = 0
while len(q):
# vは数字, 親のノードのインデックス
v = q.pop()
for e in tree[v]:
if distant[e] < distant[v]+1: # 到達済みなら次のノードへ
continue
distant[e] = distant[v]+1
q.append(e)
for d in distant:
ans[d] += 1
for i in range(1, N):
print((ans[i]//2))
|
p02726
|
import heapq
INF = float('inf')
class Edge():
def __init__(self, a, b, cost):
self.a = a
self.b = b
self.cost = cost
def __str__(self):
return 'Edge: {} -> {}, cost {}'.format(self.a, self.b, self.cost)
def dijkstra(n, G, s):
dist = [INF] * n
dist[s] = 0
h = []
heapq.heappush(h, (0, s))
while h:
# 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
d, v = heapq.heappop(h)
if dist[v] < d:
continue
# vから到達可能な頂点について、距離が短くなれば更新
for e in G[v]:
if dist[e.b] > dist[v] + e.cost:
dist[e.b] = dist[v] + e.cost
heapq.heappush(h, (dist[e.b], e.b))
return dist
n, x, y = list(map(int, input().split()))
g = [[] for i in range(n)]
for i in range(n-1):
g[i].append(Edge(i, i+1, 1))
g[i+1].append(Edge(i+1, i, 1))
g[x-1].append(Edge(x-1, y-1, 1))
g[y-1].append(Edge(y-1, x-1, 1))
ans = [0] * n
for i in range(n):
for d in dijkstra(n, g, i):
ans[d] += 1
for item in ans[1:]:
print((item // 2))
|
import heapq
INF = float('inf')
def dijkstra(n, G, s):
dist = [INF] * n
dist[s] = 0
h = []
heapq.heappush(h, (0, s))
while h:
# 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
d, v = heapq.heappop(h)
if dist[v] < d:
continue
# vから到達可能な頂点について、距離が短くなれば更新
for b, cost in G[v]:
if dist[b] > dist[v] + cost:
dist[b] = dist[v] + cost
heapq.heappush(h, (dist[b], b))
return dist
n, x, y = list(map(int, input().split()))
g = [[] for i in range(n)]
for i in range(n-1):
g[i].append((i+1, 1))
g[i+1].append((i, 1))
g[x-1].append((y-1, 1))
g[y-1].append((x-1, 1))
ans = [0] * n
for i in range(n):
for d in dijkstra(n, g, i):
ans[d] += 1
for item in ans[1:]:
print((item // 2))
|
p02726
|
# coding: utf-8
DATA = """
10 4 8
""".split("\n")
def get_debug_line():
for i in DATA:
yield i
if 1:
get_line = input
else:
get_line = get_debug_line().__next__
get_line()
N, X, Y = [int(i) for i in get_line().strip().split(" ")]
X-=1
Y-=1
INF = 10 * 20
m = [[0] * N for _ in range(N)]
tt = [0] * N
#print(ret)
#print(len(ret))
for r in range(N):
for c in range(r+1, N):
m[r][c] = c - r
#m[c][r] = m[r][c]
tt[m[r][c]] += 1
m[c][r] = m[r][c]
def Set(r, c, v):
tt[m[r][c]] -= 1
m[r][c] = v
tt[m[r][c]] += 1
for r in range(N):
if m[r][X] < m[r][Y]:
Set(r, Y, m[r][X]+1)
for c in range(Y+1, N):
if m[r][c] <= m[r][c-1]:
break
Set(r, c, m[r][c-1]+1)
for c in range(Y-1, X, -1):
if m[r][c] <= m[r][c+1]:
break
Set(r,c, m[r][c+1]+1)
for t in tt[1:]:
print (t)
|
# coding: utf-8
DATA = """
10 4 8
""".split("\n")
def get_debug_line():
for i in DATA:
yield i
if 1:
get_line = input
else:
get_line = get_debug_line().__next__
get_line()
N, X, Y = [int(i) for i in get_line().strip().split(" ")]
X-=1
Y-=1
INF = 10 * 20
m = [[0] * N for _ in range(N)]
tt = [0] * N
#print(ret)
#print(len(ret))
for r in range(N):
for c in range(r+1, N):
m[r][c] = c - r
#m[c][r] = m[r][c]
tt[m[r][c]] += 1
m[c][r] = m[r][c]
def Set(r, c, v):
if m[r][c] < v:
return False
else:
tt[m[r][c]] -= 1
m[r][c] = v
tt[m[r][c]] += 1
return True
for r in range(N):
if not Set(r, Y, m[r][X]+1):
continue
for c in range(Y+1, N):
if not Set(r, c, m[r][c-1]+1):
break
for c in range(Y-1, X, -1):
if not Set(r,c, m[r][c+1]+1):
break
for t in tt[1:]:
print (t)
|
p02726
|
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
import heapq
n,x,y = list(map(int,input().split()))
G = [[]*n for i in range(n)]
for i in range(n-1):
G[i].append((i+1))
G[i+1].append(i)
x-=1;y-=1
G[x].append((y))
G[y].append((x))
# print(G)
def bfs(g,s):
n=len(g)
dist = [inf]*n
dist[s] = 0
q = collections.deque()
q.append(s)
while q:
u = q.popleft()
for v in g[u]:
if dist[v] != inf:continue
dist[v] = dist[u] + 1
q.append(v)
return dist
sets = [set() for i in range(n)]
for i in range(n-1):
dist = bfs(G,i)
for j in range(n):
sets[dist[j]].add((min(i,j),max(i,j)))
for i in range(1,n):
print((len(sets[i])))
|
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
import heapq
n,x,y = list(map(int,input().split()))
G = [[]*n for i in range(n)]
for i in range(n-1):
G[i].append((i+1))
G[i+1].append(i)
x-=1;y-=1
G[x].append((y))
G[y].append((x))
# print(G)
def bfs(g,s):
n=len(g)
dist = [inf]*n
dist[s] = 0
q = collections.deque()
q.append(s)
while q:
u = q.popleft()
for v in g[u]:
if dist[v] != inf:continue
dist[v] = dist[u] + 1
q.append(v)
return dist
D = [0]*n
for i in range(n-1):
dist = bfs(G,i)
for j in range(i+1,n):
D[dist[j]] += 1
for i in range(1,n):
print((D[i]))
|
p02726
|
#abc160 d
from collections import deque
import itertools
n,x,y=list(map(int,input().split()))
g=[[False]*n for _ in range(n)]
for i in range(n-1):
g[i][i+1]=True
g[i+1][i]=True
g[x-1][y-1]=True
g[y-1][x-1]=True
def bfs(s,e):
color=[False]*n
dis=[0]*n
q=deque()
q.append(s-1)
color[s-1]=True
while q:
now=q.popleft()
if now==(e-1):
break
for i in range(n):
if g[now][i]==True and color[i]==False:
dis[i]+=dis[now]+1
color[i]=True
q.append(i)
return dis[e-1]
l=[i for i in range(1,n+1)]
c=itertools.combinations(l,2)
ans=[0]*n
for s,e in c:
distance=bfs(s,e)
ans[distance]+=1
for i in range(1,n):
print((ans[i]))
|
n,x,y=list(map(int,input().split()))
x,y=x-1,y-1
ans=[0]*(n+1)
for i in range(n):
for j in range(i+1,n):
a=abs(i-j)
b=abs(i-x)+1+abs(y-j)
c=abs(y-i)+1+abs(x-j)
ans[min(a,b,c)]+=1
for i in range(1,n):
print((ans[i]))
|
p02726
|
N, x, y = list(map(int, input().split()))
INF = 10 ** 100
adj_mtx = [ [INF] * (N+1) for _ in range(N+1) ]
for i in range(1, N+1):
if i != N:
adj_mtx[i][i] = 0
adj_mtx[i][i+1] = 1
adj_mtx[i+1][i] = 1
adj_mtx[x][y] = 1
adj_mtx[y][x] = 1
for k in range(1, N+1):
for i in range(1, N+1):
for j in range(1, N+1):
adj_mtx[i][j] = min(adj_mtx[i][j], adj_mtx[i][k] + adj_mtx[k][j])
for i in range(1, N):
print((sum([ r.count(i) for r in adj_mtx ]) // 2))
|
N, X, Y = list(map(int, input().split()))
result = [0] * N
for i in range(1, N):
for j in range(i+1, N+1):
step = min( j-i, abs(i-X)+1+abs(j-Y), abs(i-Y)+1+abs(j-X))
result[step] += 1
for e in result[1:]: print(e)
|
p02726
|
N, X, Y= list(map(int, input().split()))
Count = []
for i in range(N-1):
Count.append(0)
for k in range(1, N):
for i in range(1, N):
for j in range(i+1, N+1):
if (j-i > k) & ((abs(i-X) +abs(j-Y) +1)>k) & ((abs(i-X) +abs(j+1-Y) +1 )>(abs(i-X) +abs(j-Y) +1)>k):
break
if j-i <= (abs(i-X) +abs(j-Y) +1):
if j-i == k:
Count[k-1] = Count[k-1]+1
else:
if (abs(i-X) +abs(j-Y) +1) == k:
Count[k-1] = Count[k-1]+1
for i in range(N-1):
print((Count[i]))
|
N, X, Y= list(map(int, input().split()))
Count = [0]*(N-1)
for i in range(1, N):
for j in range(i+1, N+1):
Count[min(j-i, (abs(i-X) +abs(j-Y) +1), (abs(i-Y) +abs(j-X) +1))-1] += 1
for i in range(N-1):
print((Count[i]))
|
p02726
|
n,x,y = list(map(int, input().split()))
ans = [0]*n
for i in range(n):
for j in range(1,n-i):
d = min(j, abs(x-1-i)+abs(y-1-(i+j))+1, abs(x-1-(i+j))+abs(y-1-i)+1)
ans[d] += 1
for m in range(1,n):
print((ans[m]))
|
n,x,y = list(map(int, input().split()))
ans = [0]*(n-1)
for i in range(n):
for j in range(1,n-i):
d = min(j, abs(x-1-i)+abs(y-1-(i+j))+1)
ans[d-1] += 1
for m in range(n-1):
print((ans[m]))
|
p02726
|
import itertools
import collections
N, X, Y = list(map(int, input().split()))
pos = [i for i in range(1,N+1)]
ways = list(itertools.combinations(pos,2))
dist_l = [min(abs(i-j), abs(i - X) + 1 + abs(Y - j)) for i,j in ways]
dic = collections.Counter(dist_l)
for i in range(1,N):
print((dic[i]))
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
dist_l = [0] * N
for i in range(N):
for j in range(i+1,N):
dist_l[min(j-i, abs(i - X) + 1 + abs(Y - j))] += 1
for i in range(1,N):
print((dist_l[i]))
|
p02726
|
n,x,y = list(map(int,input().split()))
ans = [0 for i in range(n)]
for i in range(n):
for j in range(i,n):
p= min(abs(i-j),(abs(i-(x-1))+1+abs(y-1-j)),(abs(i-(x-1))+1+abs(y-1-j)))
ans[p] += 1
for i in range(1,n):
print((ans[i]))
|
n,x,y = list(map(int,input().split()))
ans = [0 for i in range(n)]
for i in range(n):
for j in range(i,n):
ans[min(abs(i-j),(abs(i-(x-1))+1+abs(y-1-j)),(abs(i-(x-1))+1+abs(y-1-j)))] += 1
for i in range(1,n):
print((ans[i]))
|
p02726
|
N, X, Y = list(map(int, input().split()))
dis = []
for i in range(1, N):
for j in range(i + 1, N + 1):
d = min(abs(i - j),
abs(i - X) + 1 + abs(j - Y),
abs(i - Y) + 1 + abs(j - X))
dis.append(d)
for k in range(1, N):
print((dis.count(k)))
|
N, X, Y = list(map(int, input().split()))
dis = [0 for _ in range(N)]
for i in range(1, N):
for j in range(i + 1, N + 1):
d = min(abs(i - j),
abs(i - X) + 1 + abs(j - Y),
abs(i - Y) + 1 + abs(j - X))
dis[d] += 1
for k in range(1, N):
print((dis[k]))
|
p02726
|
def warshallFloyd(n,l):
for k in range(n):
for i in range(n):
for j in range(n):
l[i][j]=min(l[i][j],l[i][k]+l[k][j])
return l
n,x,y=list(map(int,input().split()))
l=[[float('inf') for i in range(n)] for i in range(n)]
for i in range(n):
l[i][i]=0
for i in range(n-1):
l[i][i+1]=1
l[i+1][i]=1
l[x-1][y-1]=1
l[y-1][x-1]=1
distance=warshallFloyd(n,l)
ans=[0]*n
for i in range(n-1):
for j in range(i+1,n):
ans[distance[i][j]]+=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):
for j in range(i+1,n+1):
distance=min(j-i,abs(x-i)+1+abs(j-y))
ans[distance]+=1
for i in range(1,n):
print((ans[i]))
|
p02726
|
n,x,y = map(int,input().split())
ans = [0]*(n-1)
for i in range(n):
tbl = [0]*n
for j in range(i,n):
tbl[j] = min(abs(j+1-i-1),abs(i+1-x)+1+abs(j+1-y))
for i in range(1,n):
ans[i-1] += tbl.count(i)
[print(i) for i in ans]
|
n,x,y = map(int,input().split())
ans = [0]*(n)
for i in range(n):
tbl = [0]*n
for j in range(i,n):
tbl[j] = min(abs(j+1-i-1),abs(i+1-x)+1+abs(j+1-y))
ans[tbl[j]] += 1
[print(i) for i in ans[1:]]
|
p02726
|
N, X, Y = [int(n) for n in input().split(" ")]
X = X - 1
Y = Y - 1
D = {}
for i in range(N):
D[i] = []
for i in range(N):
if i != N - 1:
D[i].append(i + 1)
if i != 0:
D[i].append(i - 1)
else:
D[i].append(i - 1)
D[X].append(Y)
D[Y].append(X)
def search(start):
queue = [start]
depth = 0
dic = {start: 0}
while len(queue) > 0:
depth += 1
nextQueue = []
while len(queue) > 0:
now = queue[0]
del(queue[0])
neighbors = D[now]
for n in neighbors:
if n not in dic:
nextQueue.append(n)
dic[n] = depth
queue = nextQueue
return dic
lenD = []
for i in range(N):
d = search(i)
lenD.append(d)
kcounter = [0 for _ in range(N - 1)]
for i in range(N):
for j in range(i + 1, N):
k = lenD[i][j]
kcounter[k - 1] += 1
for k in kcounter:
print(k)
|
def search(start, N, X, Y):
dist = [0 for _ in range(N)]
if start <= X:
for i in range(X):
dist[i] = abs(start - i)
for i in range(Y, N):
dist[i] = (X - start) + 1 + (i - Y)
for i in range(X, (Y - X) // 2 + X + 1):
dist[i] = (i - start)
for i in range((Y - X) // 2 + X + 1, Y):
dist[i] = (X - start) + 1 + (Y - i)
elif start >= Y:
for i in range(Y, N):
dist[i] = abs(start - i)
for i in range(X):
dist[i] = (start - Y) + 1 + (X - i)
for i in range(X, (Y - X) // 2 + X):
dist[i] = (start - Y) + 1 + (i - X)
for i in range((Y - X) // 2 + X, Y):
dist[i] = (start - i)
else:
toX = min(start - X, Y - start + 1)
toY = min(Y - start, start - X + 1)
dist[start] = 0
for i in range(X):
dist[i] = (X - i) + toX
for i in range(Y, N):
dist[i] = toY + (i - Y)
for i in range(X, start):
dist[i] = min(start - i, Y - start + 1 + i - X)
for i in range(start + 1, Y):
dist[i] = min(i - start, start - X + 1 + Y - i)
return dist
def main():
N, X, Y = [int(n) for n in input().split(" ")]
#N, X, Y = 10, 3, 8
X = X - 1
Y = Y - 1
lenD = []
for i in range(N):
d = search(i, N, X, Y)
lenD.append(d)
kcounter = [0 for _ in range(N - 1)]
for i in range(N):
for j in range(i + 1, N):
k = lenD[i][j]
kcounter[k - 1] += 1
for k in kcounter:
print(k)
main()
|
p02726
|
import unittest
class TestD(unittest.TestCase):
def test_1(self):
self.assertEqual(think(5, 2, 4), [5, 4, 1, 0])
def test_2(self):
self.assertEqual(think(3, 1, 3), [3, 0])
def test_3(self):
self.assertEqual(think(7, 3, 7), [7, 8, 4, 2, 0, 0])
def test_4(self):
self.assertEqual(think(10, 4, 8), [10, 12, 10, 8, 4, 1, 0, 0, 0])
def solve():
n, x, y = read()
result = think(n, x, y)
write(result)
def read():
return read_int(3)
def read_int(n):
return read_type(int, n, sep=' ')
def read_float(n):
return read_type(float, n, sep=' ')
def read_type(t, n, sep):
return list([t(x) for x in read_line().split(sep)])[:n]
def read_line(n=0):
if n == 0:
return input().rstrip()
else:
return input().rstrip()[:n]
def think(n, x, y):
MAX_DISTANCE = 10 ** 9
result = [0] * n
adjacent_matrix = [[MAX_DISTANCE for _ in range(n)] for _ in range(n)]
for i in range(n - 1):
adjacent_matrix[i][i] = 0
adjacent_matrix[i][i + 1] = 1
adjacent_matrix[i + 1][i] = 1
adjacent_matrix[x - 1][y - 1] = 1
adjacent_matrix[y - 1][x - 1] = 1
warshall_floyd(adjacent_matrix)
for i in range(n):
for j in range(i + 1, n):
distance = adjacent_matrix[i][j]
result[distance] += 1
return result[1:]
def write(result):
for r in result:
print(r)
def warshall_floyd(matrix):
n = len(matrix)
changed = True
while changed:
changed = False
for i in range(n):
for j in range(n):
if i == j:
continue
for k in range(n):
if k == i or k == j:
continue
old_distance = matrix[i][j]
matrix[i][j] = min(matrix[i][j], matrix[i][k] + matrix[k][j])
if matrix[i][j] < old_distance:
changed = True
if __name__ == '__main__':
# unittest.main()
solve()
|
import unittest
class TestD(unittest.TestCase):
def test_1(self):
self.assertEqual(think(5, 2, 4), [5, 4, 1, 0])
def test_2(self):
self.assertEqual(think(3, 1, 3), [3, 0])
def test_3(self):
self.assertEqual(think(7, 3, 7), [7, 8, 4, 2, 0, 0])
def test_4(self):
self.assertEqual(think(10, 4, 8), [10, 12, 10, 8, 4, 1, 0, 0, 0])
def solve():
n, x, y = read()
result = think(n, x, y)
write(result)
def read():
return read_int(3)
def read_int(n):
return read_type(int, n, sep=' ')
def read_float(n):
return read_type(float, n, sep=' ')
def read_type(t, n, sep):
return list([t(x) for x in read_line().split(sep)])[:n]
def read_line(n=0):
if n == 0:
return input().rstrip()
else:
return input().rstrip()[:n]
def think(n, x, y):
result = [0] * n
for i in range(1, n):
for j in range(i + 1, n + 1):
minimum_distance = min(j - i, 1 + abs(x - i) + abs(y - j))
result[minimum_distance] += 1
return result[1:]
def write(result):
for r in result:
print(r)
if __name__ == '__main__':
# unittest.main()
solve()
|
p02726
|
n,x,y = list(map(int,input().split()))
ans=[0]*n
for i in range(1,n):
for j in range(i+1,n+1):
ans[min(abs(i-j),min(abs(i-x)+1+abs(j-y),abs(i-y)+1+abs(j-x)))]+=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):
for j in range(i+1,n+1):
ans[min(j-i,abs(i-x)+1+abs(j-y))]+=1
for i in range(1,n):
print((ans[i]))
|
p02726
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
cnt = [0] * n
for i in range(n):
for j in range(n):
if i >= j:
continue
dist = min(j - i, abs(j - y) + 1 + abs(i - x), abs(j - x) + 1 + abs(i - y))
cnt[dist] += 1
for i in range(1, n):
print((cnt[i]))
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
cnt = [0] * n
dist = []
for i in range(n):
dist.append([-1] * n)
for i in range(n):
dist[i][x] = abs(i-x)
dist[i][y] = abs(i-y)
dist[x][i] = abs(i-x)
dist[y][i] = abs(i-y)
for i in range(n):
for j in range(n):
if i >= j:
continue
dis = min(j - i, dist[j][y] + 1 + dist[i][x], dist[j][x] + 1 + dist[i][y])
cnt[dis] += 1
for i in range(1, n):
print((cnt[i]))
|
p02726
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
cnt = [0] * n
dist = []
for i in range(n):
dist.append([-1] * n)
for i in range(n):
dist[i][x] = abs(i-x)
dist[i][y] = abs(i-y)
dist[x][i] = abs(i-x)
dist[y][i] = abs(i-y)
for i in range(n):
for j in range(n):
if i >= j:
continue
dis = min(j - i, dist[i][x] + 1 + dist[y][j])
cnt[dis] += 1
for i in range(1, n):
print((cnt[i]))
|
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
cnt = [0] * n
for i in range(n):
for j in range(i+1, n):
cnt[min(j - i, abs(i-x) + 1 + abs(y-j))] += 1
for i in range(1, n):
print((cnt[i]))
|
p02726
|
n,x,y=list(map(int,input().split()))
from collections import deque
from collections import Counter
def bfs(i): # i番目の頂点を起点にしたbfs
visited=[0]*n
visited[i]=1
que=deque([])
que.append((i,1))
while len(que)>0:
di,c=que.popleft()
nm=di-1
np=di+1
no=-1
if di==x-1:
no=y-1
if di==y-1:
no=x-1
if 0<=nm and visited[nm]==0:
visited[nm]=c+1
que.append((nm,c+1))
if np<=n-1 and visited[np]==0:
visited[np]=c+1
que.append((np,c+1))
if no>=0 and visited[no]==0:
visited[no]=c+1
que.append((no,c+1))
return visited
l=[0]
myc=Counter(l)
for i in range(n):
myc += Counter(bfs(i))
ans=list(myc.values())
p=len(ans)
for i in range(2,n+1):
if i>=p:
print((0))
else:
print((ans[i]//2))
|
n,x,y=list(map(int,input().split()))
ans=[0]*(n-1)
for i in range(n-1):
for j in range(i+1,n):
ans[min(abs(i-j),abs(i-x+1)+1+abs(j-y+1))-1]+=1
for i in range(n-1):
print((ans[i]))
|
p02726
|
import itertools
from collections import Counter
N, X, Y = list(map(int, input().split()))
n_iter = itertools.combinations(list(range(1,N+1)), 2)
count_list = []
for i, j in n_iter:
#1. abs(X - i) + abs(Y - j) + 1
#2. abs(Y - i) + abs(X - j) + 1
#3. abs(j - i)
x = min(
abs(X - i) + abs(Y - j) + 1,
abs(Y - i) + abs(X - j) + 1,
abs(j - i)
)
count_list.append(x)
# 要素数の数え上げと取り出し
num_counter = Counter(count_list)
for i in range(1, N):
if i in num_counter:
print((num_counter[i]))
else:
print((0))
|
import itertools
N, X, Y = list(map(int, input().split()))
n_iter = itertools.combinations(list(range(1,N+1)), 2)
count_list = [0]*(N-1)
for i, j in n_iter:
#1. abs(X - i) + abs(Y - j) + 1
#2. abs(Y - i) + abs(X - j) + 1
#3. abs(j - i)
x = min(
abs(X - i) + abs(Y - j) + 1,
abs(Y - i) + abs(X - j) + 1,
abs(j - i)
)
count_list[x-1] += 1
for i in count_list:
print(i)
|
p02726
|
N, X, Y = list(map(int, input().split()))
INF = 1 << 30
dis = [ [abs(i-j) if abs(i-j) < 2 else INF for i in range(N)] for j in range(N)]
dis[X-1][Y-1] = 1
dis[Y-1][X-1] = 1
for k in range(N):
for i in range(N):
for j in range(N): dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])
for i in range(1, N):
ans = 0
for j in range(N): ans += dis[j].count(i)
print((ans//2))
|
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
ans = [0] * (N-1)
for i in range(N):
for j in range(i+1, N):
ans[min(j-i, abs(X-i)+1+abs(Y-j))-1] += 1
for x in ans: print(x)
|
p02726
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.