Problem:


Score : 400 points

Problem Statement

We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:

For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.

There is an edge between Vertex X and Vertex Y.

For each k=1,2,...,N-1, solve the problem below:

Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.

Constraints

3 \leq N \leq 2 \times 10^3

1 \leq X,Y \leq N

X+1 < Y

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X Y

Output

For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.

Sample Input 1

5 2 4

Sample Output 1

5
4
1
0

The graph in this input is as follows:

There are five pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 1: (1,2)\,,(2,3)\,,(2,4)\,,(3,4)\,,(4,5).

There are four pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 2: (1,3)\,,(1,4)\,,(2,5)\,,(3,5).

There is one pair (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 3: (1,5).

There are no pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 4.

Sample Input 2

3 1 3

Sample Output 2

3
0

The graph in this input is as follows:

Sample Input 3

7 3 7

Sample Output 3

7
8
4
2
0
0

Sample Input 4

10 4 8

Sample Output 4

10
12
10
8
4
1
0
0
0



Sample input:
5 2 4


Sample output:
5
4
1
0

Submission status: Wrong Answer

Solution code:
#4回目、2020-0609 BSFやりかけたが・・・
#幅優先探索
def bfs(u):
    dq =deque()
    passed =set([u])
    for i in range(1,N+1): #全頂点を始点としてBSFで距離
        dq.append(i)
        dist[(i,i)] =0   
        while dq:
            now =dq.popleft()
            for next in connection[now]:
                if next not in passed:
                    dist[(i,next)] =dist[(i,now)] +1
                    dq.append(next)
                    passed.add(next)
        passed.clear()
        for j in range(i+2):
            passed.add(j)
    return dist

#初期入力
from collections import deque 
N, x, y = map(int, input().split())

# 構造
connection ={i:set() for i in range(1,N+1)}
for i in range(1,N):
    connection[i  ].add(i+1)
    connection[i+1].add(i)
connection[x].add(y)
connection[y].add(x)

#始点からの距離をBFS
ans ={(i):[] for i in range(0,N) }
dist ={(i,j):None for i in range(1,N) for j in range(i,N+1)}
bfs(1)

for j,v in dist.items(): #j=各頂点、v=始点から各頂点の距離
    ans[v].append(j) 
for i in range(1,N):        
    print(len(ans[i]))

Submission status: Wrong Answer

Solution code:
n, x, y = map(int, input().split())

def line(n):
    if n == 0:
        return [0]
    else:
        a = []
        for i in range(1, n + 1):
            p = n - i + 1
            a.append(p)
        return a

total_in = line(n - 1 - (y - x) + 1)
left_in = line(y - 2)
right_in = line(n - x - 1)
center_out = line(y - x - 2)
left_out = line(x - 1)
right_out = line(n - y)

b = [total_in, left_in, right_in, center_out, left_out, right_out]
for i in range(len(b)):
    for j in range(len(b[i]), n - 1):
        b[i].append(0)

for i in range(n - 1):
    print(total_in[i] + left_in[i] + right_in[i] - center_out[i] - left_out[i] - right_out[i])

Submission status: Wrong Answer

Solution code:
import queue
n,x,y = map(int,input().split())

adj = [[] for i in range(n)]

adj[x-1].append(y-1)
adj[y-1].append(x-1)

for i in range(n-1):
    adj[i].append(i+1) 
    adj[i+1].append(i)
        
ans = [0 for _ in range(n+1)]

def bfs(start):
    inf = 1001001001
    q = queue.Queue()
    q.put(start)
    dist = [inf]*n
    dist[start] = 0
    
    while not q.empty():
        v = q.get()

        for i in adj[v]:
            if dist[i] == inf:
                dist[i] = dist[v] + 1
                q.put(i)

    for i in range(n):
        ans[dist[i]] += 1

for i in range(n):
    bfs(i)

for i in range(n):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n ,x , y = map(int,input().split())
x = x -1
y = y -1
ans = [0] * n
for i in range(n):
    for j in range(i+1,n):
        d = min(j -i, abs(i-x) + (j-y)+1)
        ans[d] +=1
print(*ans[1:],sep = '\n')

Submission status: Wrong Answer

Solution code:
n,x,y = map(int, input().split())
import collections

g = [[] for i in range(n)]
for i in range(n):
    if i != 0:
        g[i].append(i-1)
    if i != n-1:
        g[i].append(i+1)
g[x-1].append(y-1)
g[y-1].append(x-1)


inf = 10**5
dp = [[inf for i in range(n)] for j in range(n)]
todo = collections.deque()

for i in range(n):
    dp[i][i] = 0
    for j in g[i]:
        todo.append(j)
    while len(todo) > 0:
        now = todo.popleft()
        leng = inf
        for j in g[now]:
            if dp[i][j] == inf:
                todo.append(j)
            else:
                tem = dp[i][j] + 1
                if tem < leng:
                    leng = tem
        dp[i][now] = leng
        dp[now][i] = leng

for i in range(1,n):
    ans = 0
    for j in range(n):
        for k in range(j+1,n):
                if dp[j][k] == i:
                    ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n,x,y = map(int, input().split())
import collections

g = [[] for i in range(n)]
for i in range(n):
    if i != 0:
        g[i].append(i-1)
    if i != n-1:
        g[i].append(i+1)
g[x-1].append(y-1)
g[y-1].append(x-1)

print(g)

inf = 10**5
dp = [[inf for i in range(n)] for j in range(n)]
todo = collections.deque()

for i in range(n):
    dp[i][i] = 0
    for j in g[i]:
        todo.append(j)
    while len(todo) > 0:
        now = todo.popleft()
        leng = inf
        for j in g[now]:
            if dp[i][j] == inf:
                todo.append(j)
            else:
                tem = dp[i][j] + 1
                if tem < leng:
                    leng = tem
        dp[i][now] = leng

for i in range(1,n):
    ans = 0
    for j in range(n):
        for k in range(n):
            if j < k:
                if dp[j][k] == i:
                    ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
N, X, Y = map(int, input().split())

KK = []
for k in range(1, N):
    K = []
    for i in range(1, N):
        for j in range(i+1, N+1):  # それぞれのk,i,jについて、
            if i <= X and Y <= j:  # ショートカットできる場合。X-Y本の辺を1にできる。
                if (j-i)-(Y-X)+1 == k:
                    K.append(1)
            else:  # ショートカット関係無い場合
                if j-i == k:
                    K.append(1)
    KK.append(sum(K))

print(KK)

Submission status: Wrong Answer

Solution code:
N,X,Y=map(int,input().split())
if X > Y:
    exc=X
    X=Y
    Y=exc
L=[0]*N
for i in range(N-1):
    for j in range(i+1,N):
        if i >= Y-1 or j <= X-1 or j-1 ==1:
            L[j-i]+=1
        elif i <= X-1 and j >= Y-1:
            L[1+abs(X-1-i)+abs(Y-1-j)]+=1
#        elif i >= X-1 and i-(X-1) > (Y-1)-i:
#            L[j-i]+=1
        else:
            L1=j-i
            L2=min(j-i,1+abs(X-1-i)+abs(Y-1-j))
            L[min(L1,L2)]+=1

for i in range(1,N):
    print(L[i])

Submission status: Wrong Answer

Solution code:
N,X,Y=map(int,input().split())
if X > Y:
    exc=X
    X=Y
    Y=exc
L=[0]*N
for i in range(N-1):
    for j in range(i+1,N):
        if i >= Y-1 or j <= X-1 or j-1 ==1:
            L[j-i]+=1
        elif i <= X-1 and j >= Y-1:
            L[1+abs(X-1-i)+abs(Y-1-j)]+=1
        elif i >= X-1 and i-(X-1) > (Y-1)-i:
            L[j-i]+=1
        else:
            L1=j-i
            L2=min(j-i,1+abs(X-1-i)+abs(Y-1-j))
            L[min(L1,L2)]+=1

for i in range(1,N):
    print(L[i])

Submission status: Wrong Answer

Solution code:
import collections

N,X,Y=map(int,input().split())
if X > Y:
    exc=X
    X=Y
    Y=exc
L=[]
for i in range(N-1):
    for j in range(i+1,N):
        if i >= Y-1 or j <= X-1:
            L.append(j-i)
        elif j-i == 1:
            L.append(1)
        elif i <= X-1 or j >= Y-1:
            L.append(1+abs(X-1-i)+abs(Y-1-j))
        else:
            L1=j-i
            L2=min(j-i,1+abs(X-1-i)+abs(Y-1-j))
            L.append(min(L1,L2))

c=collections.Counter(L)

for i in range(1,N):
    print(c[i])

Submission status: Wrong Answer

Solution code:
N, X, Y = map(int, input().split())
c = [0 for i in range(N)]
print(c)
for i in range(1,N):
  for j in range(i+1,N+1):
    x = abs(X-i)
    y = abs(Y-j)
    a = min(x+y+1,j-i)
    c[a]+=1

for i in range(1,N):
  ans = c[i]
  print(ans)

Submission status: Wrong Answer

Solution code:
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) + (Y - X - 1) + abs(j - Y),
            abs(j - X) + (Y - X - 1) + abs(i - Y)
        )
        ans[d] += 1

print(*ans[1:], sep='\n')

Submission status: Wrong Answer

Solution code:
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) + (Y - X - 1) + abs(j - Y),
            abs(j - X) + (Y - X - 1) + abs(i - Y)
        )
        ans[d] += 1

print(*ans[1:])

Submission status: Wrong Answer

Solution code:
N, X, Y = map(int, input().split())
d = Y-X
c = []
for i in range(1,N):
  for j in range(i+1,N+1):
    if i == X and j == Y:
      c.append(1)
    elif i <= X and j >= Y:
      c.append(j-i-d+1)
    else:
      c.append(j-i)
for i in range(1,N):
  ans = c.count(i)
  print(ans)

Submission status: Wrong Answer

Solution code:
N, X, Y = map(int, input().split())
d = Y-X
c = []
for i in range(1,N):
  for j in range(i+1,N+1):
    if i == X and j == Y:
      c.append(1)
    elif j-i<=d:
      c.append(j-i)
    else:
      if i <= X and j >= Y:
        c.append(j-i-d+1)
      else:
        c.append(j-i)
for i in range(1,N):
  ans = c.count(i)
  print(ans)

Submission status: Wrong Answer

Solution code:
N, X, Y = map(int, input().split())
d = Y-X
c = []
for i in range(1,N):
  for j in range(i+1,N+1):
    if i == X and j == Y:
      c.append(1)
    elif j-i<=d:
      c.append(j-i)
    else:
      c.append(j-i-d+1)
for i in range(1,N):
  ans = c.count(i)
  print(ans)

Submission status: Wrong Answer

Solution code:
n, x, y = map(int, input().split())
cnt = [0] * n
# 漸化式が建てられそうでめんどくさい場合は、片方を固定する
# 端点を固定する 1..n-2 から順に大きい頂点に向かって伸びていく
for i in range(n - 1):
    for j in range(n):
        if j <= x - 1:  # 1 idx
            cnt[j - i] += 1
        elif x <= j <= y - 1:
            cnt[min(j - i, x + y - i - j - 1)] += 1
        else:
            cnt[x - y - i + j + 1] += 1
for i in range(1, n):
    print(cnt[i])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque

n,x,y = map(int,input().split())
print(n)
graph=[[] for _ in range(n)]

for i in range(1,n+1):
    if i!=x:
        if i == 1:
            graph[i-1].append(i+1)
        elif i == n:
            graph[i-1].append(i-1)
        else:
            graph[i-1].append(i-1)
            graph[i-1].append(i+1)
    else:
        graph[i-1].append(y)
        if i == 1:
            graph[i-1].append(i+1)
        elif i == n:
            graph[i-1].append(i-1)
        else:
            graph[i-1].append(i-1)
            graph[i-1].append(i+1)
k_dic=defaultdict(int)

for i in range(1,n):
    q = deque([[i]])
    prev = [0]*n
    prev[i-1] = 1
    dic=defaultdict(int)
    while q:
        now_l = q.popleft()
        tu = []
        for now in now_l:
            nex = graph[now-1]
            
            for ne in nex:
                if prev[ne-1] == 0:
                
                    tu.append(ne)
                    q.append(tu)
                    prev[ne-1] = 1
                    dic[ne] = dic[now]+1
                    if ne > i:
                        k_dic[dic[ne]] += 1

for i in range(1,n):
    print(k_dic[i])

Submission status: Wrong Answer

Solution code:
from collections import deque

if __name__ == '__main__':

    n, x, y = map(int, input().split())

    ans = [0] * (n+1)

    g = [[i+1, i-1] for i in range(n+1)]
    g[0].clear()
    g[1].pop(1)
    g[n].pop(0)

    g[x].append(y)
    g[y].append(x)

    for i in range(1,n+1):
        q = deque()
        time = 0

        visit = [False] * (n+1)

        q.append((i, time))

        while(len(q) > 0):
            item = q.popleft()

            if visit[item[0]] == False:
                visit[item[0]] = True
                ans[item[1]] += 1
                if item[1] == 5:
                    print(i,item)

                for k in g[item[0]]:
                    q.append((k, item[1]+1))

    for i in range(1,n):
        print(ans[i]//2)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n, x, y = map(int, input().split())

cnt = [0] * n
for i, j in combinations(range(n), 2):
    dist = min(abs(j - i), abs(i - x) + abs(j - y) + 1,
               abs(i - y) + abs(j - x) + 1)
    cnt[dist] += 1

for i in range(1, n):
    print(cnt[i])

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n, x, y = map(int, input().split())

cnt = [0] * n
for i, j in combinations(range(n), 2):
    dist = min(abs(j - i), abs(i - x) + abs(j - y) + 1,
               abs(i - y) + abs(j - x) + 1)
    cnt[dist] += 1

for i in range(1, n):
    print(cnt)

Submission status: Wrong Answer

Solution code:
N, X, Y = list(map(int,input().split()))

Num = [0] * N
for j in range(1, N):
  for i in range(1, j):
    D = min(j - i, abs(j - Y) + 1 + abs(i - X))
    Num[D] += 1
for k in range(1, N):
  print(Num[k])

Submission status: Wrong Answer

Solution code:
from collections import deque
def bfs(v):
    todo = deque()
    todo.append(v)
    seen[v] = 0
    while len(todo) > 0:
        v = todo.popleft()
        d = seen[v]
        for w in graph[v]:
            if seen[w] != -1:
                continue
            seen[w] = d + 1
            todo.append(w)


N, X, Y = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(N-1):
    graph[i].append(i+1)
graph[X-1].append(Y-1)

cnt = [0 for _ in range(N)]
for i in range(N-1):
    seen = [-1 for _ in range(N)]
    bfs(i)
    for j in range(i+1, N):
        cnt[seen[j]] += 1

for i in range(1, N):
    print(cnt[i])

Submission status: Wrong Answer

Solution code:
from collections import deque
from collections import defaultdict

n,x,y = map(int,input().split())

count_dict = {key:0 for key in range(1,n)}

for s in range(1,n):
    for e in range(s+1,n+1):
        if s <= x <= e:
            count_dict[min(e-s, x-s+1+abs(y-e))] += 1
        elif s <= y <= e:
            count_dict[min(e-s, s-x+1+abs(y-e))] += 1
        else:
            count_dict[e-s] += 1

for i in range(1,n):
    print(count_dict[i])


#def bfs(s):
#    que = deque()
#    que.append([s,1,0])
#
#    while que:
#        i = que.popleft()
#        #特殊例の探索
#        if i[0] == x:
#            #yへの移動ルートも計算する
#            if checked_dict[y] == 0:
#                checked_dict[y] = 1
#                que.append([y,i[1],i[2]+1])
#                counter_dict[i[2]+1] += 1
#                #checked_dict[x] = 1
#                #counter_dict[i[2]] += 1
#        elif i[0] == y:
#            #i-1への移動ルートも計算する。
#            if checked_dict[i[0]-1] == 0:
#                checked_dict[i[0]-1] = 1
#                que.append([i[0]-1,-1,i[2]+1])
#                counter_dict[i[2]+1] += 1
#                #checked_dict[y] = 1
#                #counter_dict[i[2]] += 1
#
#        #通常例の探索
#        if i[0]!=n and checked_dict[i[0]+i[1]] == 0:
#            checked_dict[i[0]+i[1]] = 1
#            que.append([i[0]+i[1],i[1],i[2]+1])
#            counter_dict[i[2]+1] += 1
#            #checked_dict[i[0]] = 1
#            #counter_dict[i[2]] += 1
#
#
#
#
#
#
#
#
#
#n,x,y = map(int,input().split())
#
#checked_dict = {key:0 for key in range(0,n+1)}
#
#counter_dict = {key:0 for key in range(1,n)}
#
#result_dict = {key:0 for key in range(1,n)}
#
#
#for s in range(1,n):
#    checked_dict = {key:0 for key in range(0,n+1)}
#    counter_dict = {key:0 for key in range(1,n)}
#    checked_dict[s] = 1
#    bfs(s)
#    for j in range(1,n):
#        result_dict[j] += counter_dict[j]
#
#
#print(counter_dict)
#
#"""
#for i in range(1,n):
#    print(counter_dict[i])
#"""
#
#
##for j in range(1,n):
##    for k in range(1,j+1): # 1~jまで
##        result_dict[k] += 1*counter_dict[j]
##
##print(result_dict)
#

Submission status: Wrong Answer

Solution code:
n,x,y=map(int,input().split())
le=x-1
ri=n-y
rnd=y-x+1
L=[0]*(n-1)
lim=rnd//2
for i in range(1,n):
    if i <= lim:
        L[i-1] += rnd

for i in range(1,le+1):
    for j in range(1,lim+1):
        L[i-1+j] += 2

for i in range(1,ri+1):
    for j in range(1,lim+1):
        L[i-1+j] += 2

for i in range(le):
    for j in range(ri):
        L[i+j+2] += 1

for i in range(le):
    L[i] += le-i
for j in range(ri):
    L[j] += ri-j

for i in range(n-1):
    print(L[i])

Submission status: Wrong Answer

Solution code:
# 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[X][Y] = 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:])))

Submission status: Wrong Answer

Solution code:
n,x,y = [int(n) for n in input().split()]


ans = [0] * (n-1)

for i in range(n-1):
    for j in range(i+1,n):
        a=j-i
        b=abs(y-j)+abs(i-x)+1
        ans[min(a,b)-1]+=1
for i in ans:
	print(i)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,X,Y = map(int, input().split())
X = X-1
Y = Y-1

num_short_root = np.zeros(N-1)
for i in range(N-1):
  for j in range(i+1,N,1):
    short_root = 0
    if i <= X and Y <= j:
      short_root = (j-i)-(Y-X-1)
    else:
      short_root = j-i
    num_short_root[short_root-1] += 1

for i in range(N-1):
  print(int(num_short_root[i]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
N, X, Y = map(int, input().split())
G = defaultdict(list)
for i in range(1, N):
    G[i].append(i+1)
    G[i+1].append(i)
print(G)

G[X].append(Y)
G[Y].append(X)

print(G)

d = [0] * N

for i in range(1, N+1):
    q = deque()
    q.append(i)
    visit = [-1]*N
    visit[i-1] = 0
    while q:
        p = q.popleft()
        for next_p in G[p]:
            if visit[next_p-1] == -1:
                visit[next_p-1] = visit[p-1] + 1
                q.append(next_p)

    for l in range(N):
        d[visit[l]] += 1

for k in range(1, N):
    print(d[k]//2)

Submission status: Wrong Answer

Solution code:
import itertools

N, X, Y = list(map(int, input().split()))

ans = [0] * N
comb = list(itertools.combinations(range(1,N+1),2))


for i in range(len(comb)):
    if comb[i][0] <= X and comb[i][1] >= Y:
        k = comb[i][1] - comb[i][0] - (Y - X) + 1
        ans[k] += 1
    elif comb[i][0] <= X:
        k = X - comb[i][0] + min(comb[i][1] - X, Y - comb[i][1]+1)
        ans[k] += 1
    elif comb[i][1] >= Y:
        k = comb[i][1] - Y + min(Y - comb[i][0], comb[i][0] - X + 1)
        ans[k] += 1
    else:
        k = comb[i][1] - comb[i][0]
        ans[k] += 1
for i in range(1,N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n, x, y = list( map( int, input().split() ) )

#1,2,...,X,Y,...,N
def a( k ):
    ver = n - ( y - 1 ) + x
    if ver < k:
        return 0
    else:
        return ver - k

#X+1,X+2,...,Y
def b( k ):
    ver = y - ( x - 1 )
    if k > ver / 2:
        return 0
    else:
        return ver

#1,2,...,X,X+1,...,Y
def c( k ):
    if k < 2 or x == 1:
        return 0
    half = ( y - ( x - 1 ) ) // 2
    scope = min( ( x + k - 1 ), ( x + half ) ) - max( 1, x - k + 1 )
    return max( 0, scope - k + 1 )

#X,X+1,...,Y,Y+1,...,N
def d( k ):
    if k < 2 or y == n:
        return 0
    half = ( y - ( x - 1 ) ) // 2
    scope = min( ( y + k - 1 ), n ) - max( ( y - half ), ( y - k + 1 ) )
    return max( 0, scope - k + 1 )

for k in range(1, n):
    ans = a(k) + b(k) + 2*c(k) + 2*d(k)
    if k == 1:
        ans -= 1    # A&B
    if k > 1 and k < x + 1 and x > 1:
        ans -= 1
    if k > 1 and k < n - ( y - 2 ) and y < n:
        ans -= 1
    #print( a(k), b(k), c(k), d(k) )
    print( max( 0, ans ) )

Submission status: Wrong Answer

Solution code:
n, x, y = list( map( int, input().split() ) )

#1,2,...,X,Y,...,N
def a( k ):
    ver = n - ( y - 1 ) + x
    if ver < k:
        return 0
    else:
        return ver - k

#X+1,X+2,...,Y
def b( k ):
    ver = y - ( x - 1 )
    if k > ver / 2:
        return 0
    else:
        return ver

#1,2,...,X,X+1,...,Y
def c( k ):
    if k < 2:
        return 0
    half = ( y - ( x - 1 ) ) // 2
    scope = min( ( x + k - 1 ), ( x + half ) ) - max( 1, x - k + 1 )
    return max( 0, scope - k + 1 )

#X,X+1,...,Y,Y+1,...,N
def d( k ):
    if k < 2:
        return 0
    half = ( y - ( x - 1 ) ) // 2
    scope = min( ( y + k - 1 ), n ) - max( ( y - half ), ( y - k + 1 ) )
    return max( 0, scope - k + 1 )

for k in range(1, n):
    ans = a(k) + b(k) + 2*c(k) + 2*d(k)
    if k == 1:
        ans -= 1
    if k > 1 and k < x + 1 and x > 1:
        ans -= 1
    if k > 1 and k < n - ( y - 2 ) and y < n:
        ans -= 1
    #print( a(k), b(k), c(k), d(k) )
    print( max( 0, ans ) )

Submission status: Wrong Answer

Solution code:
N,X,Y = map(int,(input().split()))
lList = [ 0 for i in range(N) ]
for i in range(N):
  for j in range(i + 1,N):
    l1 = j - i
    l2 = abs(X - 1 - i) + abs(Y - 1 - j)  + 1
    l = min(l1,l2)
    lList[l] += 1
    print(l,i+1,j+1)
    
for i in lList[1:]:
  print(i)

Submission status: Wrong Answer

Solution code:
mod=1000000007
n,x,y=map(int,input().split())
x-=1
y-=1
w=[[mod]*n for i in range(n)]
ans=[0]*(n-1)
for i in range(n):
    for j in range(i+1,n):
        t=j-i
        if w[i][j]==mod:
            w[i][j]=t
            ans[t-1]+=1
        elif w[i][j]>t:
            ans[w[i][j]-1]-=1
            w[i][j]=t
            ans[t-1]+=1
        if i<=x and j>x:
            z=t-(x-i)-1
            j2=y-z
            if i<j2:
                if w[i][j2]==mod:
                    w[i][j2]=t
                    ans[t-1]+=1
                elif w[i][j2]>t:
                    ans[w[i][j2]-1]-=1
                    w[i][j2]=t
                    ans[t-1]+=1
            j2=y+z
            if i<j2<=n-1:
                if w[i][j2]==mod:
                    w[i][j2]=t
                    ans[t-1]+=1
                elif w[i][j2]>t:
                    ans[w[i][j2]-1]-=1
                    w[i][j2]=t
                    ans[t-1]+=1

#print(w)
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N,X,Y=list(map(int,input().split()))
G=[]
for i in range(1,N):
    G.append([i,i+1])
G.append([X,Y])
graph=[[] for i in range(N+1)]
for i in range(N):
    u,*v=G[i]
    v.sort()
    for j in v:
        graph[u].append(j)
        graph[j].append(u)
counter=[[] for i in range(N+1)]
for j in range(1,N+1):
    stack=[j]
    visited=[-1 for i in range(N+1)]
    visited[j]=0
    while stack:
        n=stack.pop(0)
        for i in graph[n]:
            n_n=i
            if visited[n_n]<0:
                visited[n_n]=visited[n]+1
                stack.append(n_n)
    for i,value in enumerate(visited):
        for k in range(1,N):
            if value==k:
                counter[k].append([j,i])
for i,value in enumerate(counter):
    if not (i==0 or i==5):
        print(int(len(value)/2))

Submission status: Wrong Answer

Solution code:
n, x, y = map(int, input().split())


def distance(i,j):
    d = abs(i-y)+1+abs(j-x)    
    d = min(j-i, d)
    return d

d = [0]*(n-1)
for i in range(1, n+1):
    for j in range(i+1,n+1):
        d[distance(i,j)-1] = d[distance(i,j)-1] + 1

for i in d:
    print(i)

Submission status: Wrong Answer

Solution code:
n, x, y = map(int, input().split())

ans = [0]*n

x = x-1
y = y-1

def search(i, j):
    if j <= x or y <= i:
        ans[j-i] += 1
    elif i <= x and x <= j and j <= y:
        d = min(j-i, x-i+y-j+1)
        ans[d] += 1
    elif x <= i and j <= y:
        d = min(j-i, i-x+y-j+1)
        ans[d] += 1
    elif x <= i and i <= y and y <= j:
        d = min(j-i, i-x+j-y+1)
        ans[d] += 1
    elif i <= x and y <= j:
        ans[x-i+j-y+1] += 1
    
    
for i in range(0, n-1, 1):
    for j in range(i+1, n, 1):
        search(i,j)
        print(ans)
        
for i in range(1,n):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import itertools

N, X, Y = map(int, input().split())
G = [n+1 for n in range(N)]

num_pair = list(itertools.combinations(G, 2))

len_count = [0 for k in range(N-1)]
    
for i,j in num_pair:
    if i <= X and Y <= j:
        len_tmp = j-i-(Y-X-1)
    elif i <= X:
        len_tmp = min(j-i, Y-i-(Y-X-1)+Y-j)
    elif Y <= j:
        len_tmp = min(j-i, j-X-(Y-X-1)+i-X)
    else:
        len_tmp = j - i
    
    len_count[len_tmp-1] += 1 # 距離kとなる数の組合せを、インデックスk-1に格納する
    
for d in len_count:
    print(d)

Submission status: Wrong Answer

Solution code:
N,X,Y = 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-i))
        ans[mina-1] += 1
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    N, X, Y = map(int, input().split())
    dic = {key: 0 for key in range(1, N)}
    for i in range(1, N+1):
        for j in range(1, N+1):
            if(i < j):
                key = min(abs(j - i), abs(X - i)+1+abs(j - Y),
                      abs(Y - i) + 1 + abs(j - X))
                dic[key] += 1
        for ans in dic.values():
            print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]

mod=10**4
def dk(edge,vis):
    q=[vis]
    visited=[False]*N
    heapify(q)
    while len(q):
        e=heappop(q)
        cd,ce=e//mod, e%mod
        if visited[ce]:
            continue
        visited[ce]=True
        if ce>vis:
            ans[ce]+=1
        for ne in edge[ce]:
            heappush(q,(cd+1)*mod+ne)



N, X, Y = map(int,input().split()) #n:頂点数　w:辺の数
ans=[0]*(N)
edge = [[] for i in range(N)]
    #edge[i] : iから出る道の[重み,行先]の配列
for i in range(N-1):
    x,y=i,i+1
    edge[x].append(y)
    edge[y].append(x)
edge[X-1].append(Y-1)
edge[Y-1].append(X-1)

for vis in range(N-1):
    dk(edge,vis)
    #print(ans)
for a in ans[1:]:
    print(a)

Submission status: Wrong Answer

Solution code:
N, X, Y = map(int, input().split())


counts = [0] * (N-1)
for i in range(1, N):
    for j in range(i+1, N+1):
        # i -> x 直接
        d1 = abs(j-i)
        # i -> X -> Y -> j
        d2 = abs(i-X) + abs(Y-j) + 1

        d = min(d1, d2)
        print('i, j, dist', i, j, d)
        counts[d-1] += 1

for count in counts:
  print(count)

Submission status: Wrong Answer

Solution code:
import itertools

N, X, Y = 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 j == Y:
        #     dp[i][j] = dp[i][X] + 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 )
print(dp)

dp = list(itertools.chain.from_iterable(dp))
for i in range(1,N):
    print(dp.count(i))

Submission status: Wrong Answer

Solution code:
n,x,y = map(int,input().split())
c = [[n for j in range(n)] for i in range(n)]

for i,raw in enumerate(c) :
    if(i + 1 >= n) :
        continue
    q = [[i,0]]
    cnt = 0
    while len(q) > 0 :
        cnt += 1

        if(cnt > 10) :
            break
        tmp = q.pop(0)
        pos = tmp[0]
        cost = tmp[1]

        if raw[pos] <= cost :
            continue
        raw[pos] = min(raw[pos],cost)
        if pos-1 > i and pos :
            q.append([pos-1,cost+1])
        if pos+1 < n :
            q.append([pos+1,cost+1])
        if pos == x-1 :
            q.append([y-1,cost+1])


lst = []
for i in c :
    for j in i:
        lst.append(j)

for i in range(1,n):
     print(lst.count(i))

Submission status: Wrong Answer

Solution code:
import sys
# input処理を高速化する
input = sys.stdin.readline

N,X,Y = map(int,input().split())

from collections import deque

class BFS():
    def __init__(self):
        self.matrix=[]
        print("BFS class is imported!")

    def add(self,start,end,cost):
        self.matrix.append([start,end,cost])
    
    def CreateRoot(self):
        #頂点の数
        V = max([ max(i[:2]) for i in self.matrix])


        #隣接行列の作成
        self.root = [[float('inf')]*(V+1) for _ in range(V+1)]

        #その点自身の距離は0に初期化
        for j in range(V+1):
            self.root[j][j] = 0

        for e in self.matrix:
            self.root[e[0]][e[1]] = e[2]
            self.root[e[1]][e[0]] = e[2]

        # print(*self.root,sep="\n")

    def shortest_path(self,start,end):
        #頂点の数
        V = len(self.root)

        #startから各点までの距離を格納
        distance=[float('inf')] * V
        distance[start] =0

        #visited:探索済みの点
        #size:探索済みの頂点数
        visited=[0]*V
        visited[start] = 1
        size = 1

        #キュー
        d =deque()
        d.append(start)

        while size<V:
            for v in range(V):
                if self.root[d[0]][v]!=float('inf') and visited[v]==0:
                    d.append(v)

            for w in d:
                if distance[w] > distance[d[0]] + self.root[d[0]][w]:
                    distance[w] = distance[d[0]] + self.root[d[0]][w]
                    visited[w] =1
                    size+=1

            d.popleft()       

        return distance

i=BFS()

for j in range(N-1):
    i.add(j,j+1,1)

i.add(X-1,Y-1,1)

i.CreateRoot()

matrix=[]
for j in range(N):
    matrix.append(i.shortest_path(j,j+1))


print(*matrix,sep="\n")

Distances=[0]*(N+1)

for i in range(N):
    for j in range(i+1,N):
        Distances[matrix[i][j]]+=1 

for k in range(1,N):
    print(Distances[k])