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:
# N, X, Y = list(map(int, input().split()))

N = 5
X = 2
Y = 4

ans = [0]*N

for sv in range(N):
    # dist[v] = dist from sv to v
    dist = [float("inf")]*N
    last_visited = []
    dist[sv] = 0
    last_visited.append(sv)
    while last_visited:
        for v in last_visited:
            next_last_visited = []
            if v+1 < N and dist[v+1] == float("inf"):
                dist[v+1] = dist[v]+1
                next_last_visited.append(v+1)
            if v-1 >= 0 and dist[v-1] == float("inf"):
                dist[v-1] = dist[v]+1
                next_last_visited.append(v-1)
            if v == X-1 and dist[Y-1] == float("inf"):
                dist[Y-1] = dist[v]+1
                next_last_visited.append(Y-1)
            if v == Y-1 and dist[X-1] == float("inf"):
                dist[X-1] = dist[v]+1
                next_last_visited.append(X-1)
            # print(last_visited, next_last_visited)
            last_visited = next_last_visited
    for d in dist:
        ans[d] += 1

for a in ans[1:]:
    print(a//2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

# 長点数V、直接移動先とコストを記したリストg、スタート地点rをとって、
# rからiに行くまでの最低コストがdist[i]であることを意味するリストdistを返す関数
def dijkstra(V, g, r):

  dist = [INF] * V
  queue = [(0, r)]  # queueの要素(c,v)は、コストcで直接vに行けることを意味する
  dist[r] = 0  # スタート地点rにはコスト0で行ける

  while queue:
    c, v = heappop(queue)
    if dist[v] < c:  # すでに記録されているコストの方が小さいので更新不要
      continue
      for cost, t in g[v]:
        if dist[v] + cost < dist[t]:
          dist[t] = dist[v] + cost
          heappush(queue, (dist[t], t))

          return dist

        N,X,Y=map(int,input().split())
        V, E= N,N
        g = [[] for i in range(V)]

        for i in range(N-1):
          g[i].append((1, i+1))
          g[i+1].append((1, i))  # g[s]の要素(cost,t)はsからコストcostでtに直接行けることを意味する
          # g[s]の要素(cost,t)はsからコストcostでtに直接行けることを意味する
          g[X-1].append((1, Y-1))
          g[Y-1].append((1, X-1))

          INF = 10 ** 10
          ans = [0] * N

          for r in range(N):
            for i in dijkstra(V, g, r):
              if i<INF:
                ans[i]+=1

                for j in range(1, N):
                  print(ans[j] // 2)

Submission status: Wrong Answer

Solution code:
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *

input = lambda: sys.stdin.readline().rstrip()

N, X, Y = map(int, input().split())
data = [[] for i in range(N + 1)]
for i in range(1, N):
    a = i
    b = i + 1
    data[a].append(b)
    data[b].append(a)
data[X].append(Y)
data[Y].append(X)

dic = defaultdict(int)
for i in range(1,N+1):
    stack=deque([[i,0]])
    visited=set()
    visited.add(i)
    count=set()
    while stack:
        now, dist=stack.popleft()
        for j in data[now]:
            if not j in visited:
                print(stack)
                visited.add(j)
                stack.append([j,dist+1])
                dic[dist+1]+=1
for k in range(1,N):
    print(dic[k]//2)

Submission status: Wrong Answer

Solution code:
n,x,y=map(int,input().split())
#a<b
def dis(a,b):
    return min (b-a,abs(a-x)+1+abs(b-y))

# for k in range(1,n):
#   count=0
#   #i<j
#   for i in range(1,n):
#     for j in range(i+1,n+1):
#       if dis(i,j)==k:
#         count+=1
#   print(count)
ans=[0]*(n-1)
#i<j
for i in range(1,n):
  for j in range(i+1,n+1):
    ans[dis(i,j)-1]+=1
print(ans,sep="\n")

Submission status: Wrong Answer

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

ans = [0] * (n+10)

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

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque

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

edges = [[] for _ in range(N)]

for i in range(N-1):
    edges[i].append(i+1)
    edges[i+1].append(i)


edges[X-1].append(Y-1)
edges[Y-1].append(X-1)

ans = [0] * (N-1)

queue = deque([])

print(edges)
def bfs(start):
    queue.extend(edges[start])
    visited = [False] *  N
    visited[start] = True
    i = 0
    while queue:
        length = len(queue)
        for l in range(length):
            current = queue.popleft()
            if not visited[current]:
                ans[i] += 1
                if edges[current]:
                    queue.extend(edges[current])
                visited[current] = True    
        i += 1

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

for i in ans:
    print(i // 2)

Submission status: Wrong Answer

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

x = X-1
y = Y-1

a = [0]*N

for i in range(N):
    for j in range(N-i-1):
        #print i, j
        p = i+j+1
        c = min(abs(p-i), abs(x-i)+1+abs(y-p))
        a[c]+=1
        print "c=",c

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

Submission status: Wrong Answer

Solution code:
import copy
scopy = copy.deepcopy

n, x, y = list(map(int, input().split()))
total = n * (n -1) // 2
lens = []
lappend = lens.append

k = 1
s = set([(i, i+1) for i in range(1,n)])
sadd = s.add
sadd((x, y))
lappend(len(s))
s_prev = set()
prev = set()
# print(f"{k:-^80}")
# print(f"sum      ={s}")
# print(f"sum_prev ={s_prev}")
# print(f"prev     ={prev}")
# print(f"now      ={s-s_prev}")

for k in range(2, n+1):
    for a in prev:
        if a[1] == x:
            sadd((a[0], y))
        elif a[1] == y and a[0] != x:
            t = (a[0], x) if a[0] < x else (x, a[0])
            sadd(t)
        if a[1] < n:
            sadd((a[0], a[1]+1))
#     print(f"{k:-^80}")
#     print(f"sum      ={s}")
#     print(f"sum_prev ={s_prev}")
#     print(f"prev     ={prev}")
#     print(f"now      ={s-s_prev}")
    lappend(len(s)-len(s_prev))
    s_prev = scopy(s)
    prev = s_prev -prev
#     if len(s) == total:
#         break
for l in lens[1:]:
    print(l)

Submission status: Wrong Answer

Solution code:
N,X,Y = map(int, input().split())
D = [0] * N
for i in range(1,N):
  for j in range(i+1,N+1):
    D[min(abs(i-j),abs(X-i)+abs(Y-j)+1)] += 1 
print (D[1:], sep="\n")

Submission status: Wrong Answer

Solution code:
n, x, y = map(int, input().split())
ans = [0 for _ in range(n)]
for i in range(1, n+1):
    for j in range(i+1, n+1):
        if j >= y and i <= x:
            ans[j-i-(y-x-1)] += 1
        elif i <= x and x < j <= y:
            ans[min(j-i, y-j+1+x-i)] += 1
        elif x <= i < y and y <= j:
            ans[min(j-i, j-y+i-x+1)] += 1
        else:
            ans[j-i] += 1


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

Submission status: Wrong Answer

Solution code:
import heapq
def set_heapq(que, edge, used, v, add_dist=0):
    '''
    確定地点vからつながる辺を全てqueに設定し、返却する

    Parameters
    que : heapque(touple or list)
        辺を管理するキュー (距離、次の行き先)のtopuleまたはlistにて管理
    edge : list
        全ての辺を格納する二次元のリスト edge[0]にてノード0から伸びる辺であることを表し、
        edge[0] → [距離、次の行き先] を表すlistが格納されている
    v : int
        グラフ上のノード ダイクストラでは確定したノードがvにあたる
    add_dist : int
        確定した地点に足し合わせる距離 スタート地点以外では何かしらの値が追加されることになる

    Returns
    que : heapque(touple or list)
        引数queにvからつながる辺を追加したキュー
    '''
    for a,b in edge[v]:
        if used[b]:
            heapq.heappush(que,(a+add_dist,b))
    return que

def dijkstra_heap(n, s, edge):
    '''
    ダイクストラ法でsで指定された地点からの全てのノードまでの最短距離を返却
    
    Parameters
    n : int
        ノードの数
    s : int
        スタート地点
    edge : list
        全ての辺を格納する二次元のリスト edge[0]にてノード0から伸びる辺であることを表し、
        edge[0] → [距離、次の行き先] を表すlistが格納されている

    Returns
    d : list
        スタート地点から全てのノードの最短距離のリスト
    '''
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s], used[s] = 0, False
    edgelist = set_heapq([], edge, used, s)
    while len(edgelist):
        a, b = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[b]:
            continue
        d[b], used[b] = a, False
        # 確定地点vからつながる辺を全て優先度付きキューに入れる
        edgelist = set_heapq(edgelist, edge, used, b, d[b])
    return d

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

edge[X].append((1, Y))
edge[Y].append((1, X))

tmp = []
for i in range(N):
    tmp.append(dijkstra_heap(N, i, edge))

print(tmp)
ans = []
for i in range(N):
    for j in range(i+1,N):
        ans.append(tmp[i][j])

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000000)
from collections import Counter
def key(x, y):
    return str(x)+str(y)
def main2():
    # TLE
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    M = {}
    for i in range(N):
        for j in range(i, N):
            M[key(i, j)] = j - i
    
    def helper(x, y, from_cost):
        if 0 <= x <= N-1 and 0 <= y <= N-1:
            if M[key(x,y)] > from_cost+1:
                M[key(x,y)] = from_cost + 1
                cost = from_cost + 1

                helper(x-1,y, cost)
                helper(x+1,y, cost)
                helper(x,y-1, cost)
                helper(x,y+1, cost)
        
    helper(X, Y, 0)

    cost_list = Counter(list(M.values()))
    for k in range(N-1):
        print(cost_list[k+1])

from collections import deque
INF = 1e10


def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    ans = []
    for sv in range(N):
        dist = [INF for _ in range(N)]
        q = deque([])

        def push(v, d):
            if dist[v] != INF: return
            dist[v] = d
            q.append(v)

        push(sv, 0)

        while q:
            sv = q.popleft()
            d = dist[sv]
            if sv > 0:
                push(sv-1, d+1)
            if sv < N-1:
                push(sv+1, d+1)
            if sv == X:
                push(Y, d+1)
            if sv == Y:
                push(X, d+1)
        ans += dist
    
    for k in range(1, N+1):
        print(ans.count(k) // 2)


main()

Submission status: Wrong Answer

Solution code:
# Problem D - Line++

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

# initialization
INF = 10*18
graph = [[0]*N for i in range(N)]
kyori_graph = [[INF]*N for i in range(N)]
kosu_list = [0]*(N-1)
for i in range(N):
    for j in range(i, N):
        if i==j:
            continue
        if j==i+1:
            graph[i][j] = 1
            kyori_graph[i][j] = 1
        else:
            kyori_graph[i][j] = INF
graph[X-1][Y-1] = 1
kyori_graph[X-1][Y-1] = 1

# graph search
for i in range(N):
    for j in range(i+1, N):
        # グラフの更新
        kyori_graph[i][j] = min(kyori_graph[i][j], abs(j-i), abs(X-1-i)+1+abs(j-(Y-1)), abs((Y-1)-i)+1+abs(j-(X-1)))

# 個数の数え上げ
for i in range(N):
    for j in range(i, N):
        if i==j:
            continue
        kyori = kyori_graph[i][j]
        kosu_list[kyori-1] += 1

# output
for k in kosu_list:
    print(k)

Submission status: Wrong Answer

Solution code:
# Problem D - Line++

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

# initialization
INF = 10*18
graph = [[0]*N for i in range(N)]
kyori_graph = [[INF]*N for i in range(N)]
kosu_list = [0]*(N-1)
for i in range(N):
    for j in range(i, N):
        if i==j:
            continue
        if j==i+1:
            graph[i][j] = 1
            kyori_graph[i][j] = 1
        else:
            kyori_graph[i][j] = INF
graph[X-1][Y-1] = 1
kyori_graph[X-1][Y-1] = 1

# graph search
for i in range(N):
    for j in range(i, N):
        if i==j or j==i+1:
            continue
        # グラフの更新
        kyori_graph[i][j] = min(kyori_graph[i][j], abs(j-i), abs(X-1-i)+1+abs(j-(Y-1)), abs((Y-1)-i)+1+abs(j-(X-1)))

# 個数の数え上げ
for i in range(N):
    for j in range(i, N):
        if i==j:
            continue
        kyori = kyori_graph[i][j]
        kosu_list[kyori-1] += 1

# output
for k in kosu_list:
    print(k)

Submission status: Wrong Answer

Solution code:
# Problem D - Line++

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

# initialization
INF = 10*18
graph = [[0]*N for i in range(N)]
kyori_graph = [[INF]*N for i in range(N)]
kosu_list = [0]*(N-1)
for i in range(N):
    for j in range(i, N):
        if i==j:
            continue
        if j==i+1:
            graph[i][j] = 1
            kyori_graph[i][j] = 1
        else:
            kyori_graph[i][j] = INF
graph[X-1][Y-1] = 1
kyori_graph[X-1][Y-1] = 1

# graph search
for i in range(N):
    for j in range(i, N):
        if i==j or j==i+1:
            continue
        # グラフの更新
        kyori_graph[i][j] = min(kyori_graph[i][j], abs(j-i), abs(X-1-i)+1+abs(j-(Y-1)))

# 個数の数え上げ
for i in range(N):
    for j in range(i, N):
        if i==j:
            continue
        kyori = kyori_graph[i][j]
        kosu_list[kyori-1] += 1

# output
for k in kosu_list:
    print(k)

Submission status: Wrong Answer

Solution code:
N,X,Y=map(int,input().split())
l=[0]*N
for i in range(1,N):
    for j in range(i):
        l[min(abs(i-j-1),abs(X-j-1)+abs(Y-i-1))]+=1
print(*l,sep="\n")

Submission status: Wrong Answer

Solution code:
import sys
# sys.stdin = open('input.txt')

from collections import deque

class Node:
    def __init__(self, num=None):
        self.num = num
        self.next = []
        self.visited = False

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

nodes = []
q = deque()
ans = [0] * n

x -= 1
y -= 1

for i in range(n):
    node = Node(i)
    nodes.append(node)

for i in range(n-1):
    node = nodes[i]
    node.next.append(nodes[i+1])
    if i == x:
        node.next.append(nodes[y])

# Select the initial node
for i in range(n):
    # Initialize
    dist = [0] * n
    for node in nodes:
        node.visited = False

    # add the initial node
    q.append(nodes[i])

    # BFS
    while len(q) > 0:
        node = q.popleft()
        node.visited = True

        if node.next is not None:
            for next_node in node.next:
                if not next_node.visited:
                    dist[next_node.num] = dist[node.num] + 1
                    next_node.visited = True
                    q.append(next_node)
    # print(i, dist)
    for i in range(n):
        ans[i] += dist.count(i)

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

Submission status: Wrong Answer

Solution code:
import copy
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 = []

for p in range(N):
    ans.append(sum(A, []))
    print(ans)
for t in range(N):
    if t == 0:
        continue
    sum =  A.count(t)
    print(ans[0].count(t))

Submission status: Wrong Answer

Solution code:
n,x,y = map(int,input().split())
dist = [0]*(n-1)
for i in range(n):
  for j in range(i+1,n):
    dist[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(dist[i])

Submission status: Wrong Answer

Solution code:
import copy
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
for t in range(N):
    if t == 0:
        continue
    sum = 0
    sum =  A.count(t)
    print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x,y=map(int,input().split())
x-=1; y-=1
C=[0]*(n-1)

for i in range(n):
  for j in range(i+1,n):
    d=min(j-i,abs(x-i)+abs(y-j)+1)
    C[d]+=1

print(*C)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import heapq

def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    d = [10**10]*n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

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

edge = tuple([] for i in range(n))
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w):
    if i == 0:
        edge[i].append([1,i+1])
    elif i == w-1:
        edge[i].append([1,i-1])
    else:
        edge[i].append([1,i+1])
        edge[i].append([1,i-1])
edge[X-1].append([1,Y-1])
edge[Y-1].append([1,X-1])

ans = [0]*(N+1)
tmp = []
for i in range(N):
    print(dijkstra_heap(i,edge))
    tmp.append(dijkstra_heap(i,edge)[i+1:])

for i in range(N):
    for j in tmp[i]:
        ans[j] += 1

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

Submission status: Wrong Answer

Solution code:
def inpl():
    return list(map(int, input().split()))


N, X, Y = inpl()
X -= 1
Y -= 1
ans = {}
for i in range(N):
    for j in range(i + 1, N):
        c = min(j - i, abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(i - X))
        ans[c] = ans.get(c, 0) + 1

for i in range(1, N):
    print(ans.get(i, 0))

Submission status: Wrong Answer

Solution code:
N, X, Y = map(int, input().split())
dis = []
for i in range(1, N-1):
  for j in range(i+1, N):
    d = min(j-i, abs(i-X)+1+abs(j-Y))
    dis.append(d)
    
for k in range(1,N-1):
  a = dis.count(k)
  print(a)

Submission status: Wrong Answer

Solution code:
N, X, Y = map(int, input().split())
dis = []
for i in range(1, N-1):
  for j in range(i+1, N):
    d = min(j-i, abs(i-X)+1+abs(j-Y), abs(j-X)+1+abs(i-X))
    dis.append(d)
    
for k in range(N-1):
  a = dis.count(k + 1)
  print(a)

Submission status: Wrong Answer

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

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

def bfs(i, j):
    dist = [-1]*N
    dist[i] = 0
    que = collections.deque([])
    que.append(i)
    
    while len(que) != 0:
        v = que.popleft()
        for nv in graph[v]:
            if dist[nv] != -1 or nv < v:continue
            dist[nv] = dist[v]+1
            if nv == j:break
            que.append(nv)
    return dist[j]

graph = {}
for i in range(N):
    graph[i] = set()

for i in range(N-1):
    graph[i].add(i+1)
    graph[i+1].add(i)
graph[X-1].add(Y-1)
graph[Y-1].add(X-1)

ans = [0]*N
for i in range(N):
    for j in range(i+1,N):
        d = bfs(i,j)
        ans[d] += 1
for i in range(N):
    if i == 0:continue
    print(ans[i])

Submission status: Wrong Answer

Solution code:
N, X, Y = map(int, input().split())
dis = []
for i in range(1, N-1):
  for j in range(i+1, N):
    d = min(j-i, abs(i-X)+1+abs(j-Y))
    dis.append(d)
    
for k in range(N-1):
  a = dis.count(k + 1)
  print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.sparse
N,X,Y = (int(x) for x in input().split())
lil = scipy.sparse.lil_matrix((N, N))
for i in range(N-1):
    lil[i, i+1] = 1
lil[X-1, Y-1] = 1
lil2 = scipy.sparse.csgraph.dijkstra(lil)
for i in range(1,N):
    print(np.count_nonzero(lil2 == i))

Submission status: Wrong Answer

Solution code:
import sys
import math
import numpy

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

k = [0] * (n-1)

for i in range(n):
    for j in range(i+1,n):
        cost = min( j-i , abs( (x-1) - i ) + 1 + abs( j-(y-1) )  )
        print("(i,j) : (" , i ,"," , j,") " , cost )
        k[cost - 1 ] += 1

[print(p) for p in k]

Submission status: Wrong Answer

Solution code:
n,x,y=map(int, input().split())
es=[[] for _ in range(n)]
for i in range(n):
    if i<n-1:
        es[i].append([1,i+1])
    if i>0:
        es[i].append([1,i-1])
    es[x-1].append([1,y-1])
    es[y-1].append([1,x-1])

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 es[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 es[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

from collections import defaultdict, Counter

ans=defaultdict(int)
dists=[]
for i in range(n-1):
    a=dijkstra_heap(i)[i+1:]

Submission status: Wrong Answer

Solution code:
from sys import stdin


def get_result(data):
    N, X, Y = data
    min_dist = []
    count = {}
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            min_dist.append(min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)]))


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
    get_result(data)

Submission status: Wrong Answer

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

ans_list = [0]*(n)
for i in range(1, n+1):
    for j in range(1, n+1):
        if i>j:
            min_dis = min(abs(j-i), abs(x-i) + 1 + abs(j-y), abs(y-i)+1+abs(j-x))
            ans_list[min_dis] += 1

for i, value in enumerate(ans_list):
    print(value)

Submission status: Wrong Answer

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

print(N)

for k in range(2, N):
    cnt = 0
    for i in range(1, N + 1):
        if X < i and i + k <= N:
            cnt += 1
        if i <= X and X - i + 1 == k:
            cnt += 2
        if i <= X and X - i + 2 <= k:
            if Y - (k - (X - i + 1)) > i + k:
                cnt += 2
            if Y - (k - (X - i + 1)) == i + k:
                cnt += 1
            if Y + (k - (X - i + 1)) <= N:
                cnt += 1
        if i + k <= X:
            cnt += 1
        if X < i and i+k < Y:
            if i + k > Y-(k-(i-X+1)) and k-(i-X+1) >= 0:
                cnt += 1
                if Y+(k-(i-X+1)) <= N:
                    cnt += 1
    print(cnt)

Submission status: Wrong Answer

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

print(N)

for k in range(2, N):
    cnt = 0
    for i in range(1, N + 1):
        if X < i and i + k <= N:
            cnt += 1
        if i <= X and X - i + 1 == k:
            cnt += 2
        if i <= X and X - i + 2 <= k:
            if Y - (k - (X - i + 1)) > i + k:
                cnt += 2
            if Y - (k - (X - i + 1)) == i + k:
                cnt += 1
            if Y + (k - (X - i + 1)) <= N:
                cnt += 1
        if i + k <= X:
            cnt += 1
        if X < i:
            if i + k > Y-(k-(i-X+1)) and k-(i-X+1) >= 0:
                cnt += 1
                if Y+(k-(i-X+1)) <= N:
                    cnt += 1
    print(cnt)

Submission status: Wrong Answer

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

print(N)

for k in range(2, N):
    cnt = 0
    for i in range(1, N + 1):
        if X < i and i + k <= N:
            cnt += 1
        if i <= X and X - i + 1 == k:
            cnt += 2
        if i <= X and X - i + 2 <= k:
            if Y - (k - (X - i + 1)) > i + k:
                cnt += 2
            if Y - (k - (X - i + 1)) == i + k:
                cnt += 1
            if Y + (k - (X - i + 1)) <= N:
                cnt += 1
        if i + k <= X:
            cnt += 1
        if X < i:
            if i + k > Y-(k-(i-X+1)) and k-(i-X+1) >= 0:
                cnt += 1
                if Y+(k-(i-X+1)) <= N:
                    cnt += 1



    print(cnt)

Submission status: Wrong Answer

Solution code:
import sys,math
sys.setrecursionlimit(10**9)
from collections import defaultdict
 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())


n,x,y=IA()
ans=[0 for i in range(0,n)]


def out():
    for i in range(1,n):
        print(ans[i])
    print()
if x==y:
    for i in range(1,n+1):
        ans[i]=n-i
else:

    m=x+n-y+1

    for i in range(1,m+1):
        ans[i]=m-i
        
    cha=y-x-1
    for i in range(1,cha+1):
        ans[i]+=cha-i
    #out()
    tt=cha//2+1

    def f(tt,x,t=0):
        if tt==1 and x==1:
            ans[1+t]+=1
        add=0
        for i in range(1+t,max(tt,x)+t):
            
            if i<=min(x,tt)+t:
                add+=1
            #print(str(i)+" "+str(add))
            ans[i]+=add
        add=min(x,tt)
        for i in range(max(tt,x)+t,max(tt,x)+min(x,tt)+t):
            #print(str(i)+":"+str(add))
            ans[i]+=add
            add-=1
    if cha%2==1:
        f(tt,x)
        #out()
        f(tt-1,n-y+1,1)
        #out()
        f(tt,n-y+1)
        #out()
        f(tt-1,x,1)

        
    else:
        f(tt-1,x)
        #out()
        f(tt-1,n-y+1,1)
        #out()
        
        f(tt-1,n-y+1)
        #out()
        f(tt-1,x,1)
for i in range(1,n):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
N, X, Y = map(int, input().split())
cnt = [0] * (N + 1)
for i in range(1, N):
    for j in range(i + 1, N + 1):
        if i < X:  # i = B
            if j < X:  # j = B
                cnt[j - i] += 1
                # print('1 i j idx', i, j, j - i)
            elif j < Y:  # j = A
                idx = min(j - i, X - i + 1 + Y - j)
                cnt[idx] += 1
                # print('2 i j idx', i, j, idx)
            else:  # j = z
                cnt[(X - i + 1) + (j - Y)] += 1
                # print('3 i j idx', i, j, (X - i + 1) + (j - Y))
        elif i == X:
            if j < Y:  # j = A
                idx = min(j - X, Y - j + 1)
                cnt[idx] += 1
                # print('4 i j idx', i, j, idx)
            elif j == Y:
                cnt[1] += 1
                # print('5 i j idx', i, j, 1)
            else:
                cnt[j - Y + 1] += 1
                # print('6 i j idx', i, j, j - Y + 1)
        elif i < Y:  # i = A
            # if j < X:  # j = B
            #     cnt[j - i] += 1
            if j < Y:  # j = A
                cnt[j - i] += 1
                # print('7 i j idx', i, j, j - i)
            elif j == Y:
                idx = min(j - i, i - X + 1)
                cnt[idx] += 1
                # print('8 i j idx', i, j, idx)
            else:  # j = z
                idx = min(Y - i, i - X + 1) + (j - Y)
                cnt[idx] += 1
                # print('9 i j idx', i, j, idx)
        else:  # i = Z
            cnt[j - i] += 1
            # print('10i j idx', i, j, j - i)

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

# 1 2 3 4 5

# 1 4 -> 5
# 2 3 -> 4
# 3 2 -> 1
# 4 1 -> 0

# A--------_
#  \_____X - Y - Z
# B_____/

# B < X < A < Y < Z
# B - A: 変化なし
# B - X: 変化なし
# B - Y: Y - B -> X - B + 1
# B - Z: Z - B -> (X - B + 1) + (Z - Y)

# A - X: min(A - X, Y - A + 1)
# A - Y: min(Y - A, X - A + 1)
# A - Z: min(Y - A, X - A + 1) + (Z - Y)

# X - Y: Y - X -> 1
# X - Z: Z - X -> 1 + Z - Y

# Y - Z: 変化なし

# 10 4 8

# 1 2 3 4 5 6 7
#     \______/
# 1 2 3 4 5 6 7 8 9 10
#       \______/

Submission status: Wrong Answer

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

links = [[] for i in range(n)]
for i in range(1, n):
        links[i-1].append(i)
        links[i].append(i-1)
links[x-1].append(y-1)
links[y-1].append(x-1)

ans = [0] * n
for i in range(n):
        dist = [1e5] * n
        used = [0] * n
        que = Queue()
        que.put([i, 0])
        while not que.empty():
                v, dis = que.get()
                used[v] = True
                for to in links[v]:
                        if not used[to]:
                                dist[to] = min(dist[to], dis)
                                que.put([to, dis+1])
                                ans[dis+1]+=1
for i in range(n-1): print(ans[i]//2)

Submission status: Wrong Answer

Solution code:
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
            print(i,j,1,nagasa)
        elif i < x and x < j and j < y:
            nagasa = x-i + min(j-x,y-j+1)
            print(i,j,2,nagasa)
        elif i < x and y <= j:
            nagasa = x-i + j - y + 1
            print(i,j,3,nagasa)
        elif x <= i and i < y and j <= y:
            nagasa = min(j-i,i-x+y-j+1)
            print(i,j,4,nagasa)
        elif x <= i and i < y and y < j:
            nagasa = j - y + min(y-i,i-x+1)
        elif y <= i:
            nagasa = j -i
            print(i,j,5,nagasa)
        count[nagasa] += 1
for i in range(1,n):
    print(count[i])

Submission status: Wrong Answer

Solution code:
n , x , y = map(int,input().split())
p = [[0 for i in range(j+1)] for j in range(n)]
for i in range(1,n+1):
    for j in range(1,i+1):
        p[i-1][j-1] = min(abs(i-j),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y))

for i in range(1,n+1):
    ans = 0
    for j in range(n):
        ans += p[j].count(i)
    print(ans)

Submission status: Wrong Answer

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

ans = [0] * (N - 1)

for i in range(1, N + 1, 1):
    for j in range(i + 1, N + 1, 1):
        tmp = min(
            abs(j - i),
            abs(X - i) + 1 + abs(j - Y),
            abs(X - j) + 1 + abs(i - Y) # このパターンは
        )
        ans[tmp - 1] += 1

for a in ans:
    print(ans)