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: Accepted

Solution code:
from collections import deque
inf=10**9


def BFS(num):
    color=["white" for _ in range(n+1)]
    D=[inf for _ in range(n+1)]
    queue=deque([num])

    color[num]="gray"
    D[num]=0

    while len(queue)>0:
        u=queue.popleft()
        for i in M[u]:
            if color[i]=="white" and D[u]+1<D[i]:
                D[i]=D[u]+1
                color[i]="gray"
                queue.append(i)
        color[u]="black"

    return D


n,x,y=map(int,input().split())
M=[[] for _ in range(n+1)]
for i in range(1,n):
    M[i].append(i+1)
    M[i+1].append(i)
M[x].append(y)
M[y].append(x)

ans=[0 for _ in range(n-1)]
for i in range(1,n+1):
    for j in BFS(i)[i+1:]:
        ans[j-1] +=1

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n,x,y = map(int,input().split())
cnt_l = [0]*n
from collections import deque
def bfs(start):
    queue = deque()
    queue.append(start)
    isSearched = [-1]*(n+1)
    isSearched[start] = 0
    while(queue):
        i = queue.popleft()
        cnt = isSearched[i]
        if(i==x):
            nex_l = (i-1,y,i+1)
        elif(i==y):
            nex_l = (i-1,x,i+1)
        else:
            nex_l = (i-1,i+1)

        cnt += 1
        for j in nex_l:
            if(j < 1 or n < j):
                continue
            if(isSearched[j]!=-1):
                continue
            queue.append(j)
            isSearched[j] = cnt
            cnt_l[cnt] += 1
            
        
 
        
for i in range(1,n+1):
    bfs(i)
 
 
for i in range(1,n):
    print(cnt_l[i]//2)

Submission status: Accepted

Solution code:
n,x,y = map(int,input().split())
cnt_l = [0]*n
from collections import deque
def bfs(start):
    queue = deque()
    queue.append(start)
    isSearched = [-1]*(n+1)
    isSearched[start] = 0
    while(len(queue)>0):
        i = queue.popleft()
        cnt = isSearched[i]
        if(i==x):
            nex_l = (i-1,y,i+1)
        elif(i==y):
            nex_l = (i-1,x,i+1)
        else:
            nex_l = (i-1,i+1)

        cnt += 1
        for j in nex_l:
            if(j < 1 or n < j):
                continue
            if(isSearched[j]!=-1):
                continue
            queue.append(j)
            isSearched[j] = cnt
            cnt_l[cnt] += 1
            
        
 
        
for i in range(1,n+1):
    bfs(i)
 
 
for i in range(1,n):
    print(cnt_l[i]//2)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
import os
from collections import deque
import collections

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n, x, y = map(int, input().split())

    ans = []

    for i in range(1, n + 1):

        que = deque()
        que.append(i)
        work_ans = [9999 for i in range(n + 1)]
        work_ans[i] = 0

        while len(que) is not 0:

            now = que.pop()
            # 移動する方向を設定
            target = []
            if now > 1:
                target.append(now - 1)
            if now < n:
                target.append(now + 1)
            if now == x:
                target.append(y)
            if now == y:
                target.append(x)

            for j in target:
                # 既に最適解が設定されている場合は処理をしない
                if work_ans[j] < work_ans[now] + 1:
                    continue
                # 最適解の設定と、キュー追加を実施。
                work_ans[j] = work_ans[now] + 1
                que.appendleft(j)

        ans += work_ans

    # Counter()で、各数字の個数を数える。
    counter = collections.Counter(ans)

    # 各距離の個数を出力(全網羅しているので、「÷2」して集計時の重複を排除する。)
    for i in range(1, n):
        print(counter.get(i, 0)//2)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """5 2 4"""
        output = """5
4
1
0"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3 1 3"""
        output = """3
0"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """7 3 7"""
        output = """7
8
4
2
0
0"""
        self.assertIO(test_input, output)

    def test_input_4(self):
        test_input = """10 4 8"""
        output = """10
12
10
8
4
1
0
0
0"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n,x,y = IL()
    x -= 1
    y -= 1
    dist = [0]*(n-1)
    for i in range(n):
        for j in range(i+1,n):
            dist[min(abs(j-i),abs(j-x)+abs(x-i),abs(y-j)+abs(x-i)+1)-1] += 1
    for rep in dist:
        print(rep)
    return

if __name__=='__main__':
    Main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x,y = map(int,input().split())
ans = [0] * (n-1)
l = list(range(1,n+1))

import itertools

for a,b in itertools.combinations(l, 2):
    dis = min(b-a, abs(b-y)+abs(x-a)+1)
    ans[dis-1] += 1

for i in ans:
    print(i)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

rlt = [0]*N

for i in range(1,N+1):
  for j in range(i+1,N+1):
    if (i < X and j < X) or (i > Y and j > Y):
      rlt[j-i] += 1
    elif i < X and j > Y:
      rlt[X-i+j-Y+1] += 1
    elif i < X and j <= Y:
      rlt[min(j-i,X-i+1+Y-j)] += 1
    elif i >= X and j > Y:
      rlt[min(j-i,i-X+1+j-Y)] += 1
    elif i >= X and j <= Y:
      rlt[min(j-i,i-X+Y-j+1)] += 1
      
for i in rlt[1:]:
  print(i)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

count = [0]*(N+1)
for i in range(1, N+1):
    for k in range(i+1, N+1):
        distik = min(k-i, abs(k-X) + abs(i - Y)+1, abs(k-Y) + abs(i-X)+1)
        count[distik] += 1

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

Submission status: Accepted

Solution code:
n, x, y = 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])

Submission status: Accepted

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

ans = [0] * N
 
for i in range(N-1):
  for j in range(i+1, N):
    d = min(j-i, abs(i-X) + abs(j-Y) + 1)
    ans[d] += 1

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

Submission status: Accepted

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

L = [0 for _ in range(N)]
for i in range(1, N):
    for j in range(i+1, N+1):
        l = min(abs(j-i), abs(X-i) + 1 + abs(Y-j))
        L[l] += 1
for l in L[1:]:
    print(l)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def dist(i, j, X, Y):
    a = j - i
    b = abs(X - i) + 1 + abs(j - Y)
    return min(a, b)


def solve():
    N, X, Y = Scanner.map_int()
    ans = [0 for _ in range(1, N + 1)]
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            d = dist(i, j, X, Y)
            ans[d] += 1

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


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def dist(i, j, X, Y):
    if j <= X:
        return j - i
    if i >= Y:
        return j - i
    if i <= X < Y <= j:
        return X - i + 1 + j - Y
    if X <= i < j <= Y:
        d1 = j - i
        d2 = i - X + 1 + Y - j
        return min(d1, d2)
    if i <= X <= j <= Y:
        d1 = j - i
        d2 = X - i + 1 + Y - j
        return min(d1, d2)
    else:
        d1 = j - i
        d2 = i - X + 1 + j - Y
        return min(d1, d2)


def solve():
    N, X, Y = Scanner.map_int()
    ans = [0 for _ in range(1, N + 1)]
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            d = dist(i, j, X, Y)
            ans[d] += 1

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


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

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

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

print(*ans[1:])

Submission status: Accepted

Solution code:
#ごり押し

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
import numpy as np
from collections import Counter

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

start = list(range(0, N-1)) + list(range(1, N)) + [X-1, Y-1] 
end = list(range(1, N)) + list(range(0, N-1)) + [Y-1, X-1]
cost = [1] * len(start)

graph = csr_matrix((cost, (start, end)))
lengths = dijkstra(graph, directed = False)

c = Counter(lengths.astype(np.int64).reshape(-1))
for k in range(1, N):
    print(c[k]//2)

Submission status: Accepted

Solution code:
# # -*- coding: utf-8 -*-

#
N, X, Y = map(int, input().split(' '))
edges = [(i, i+1) for i in range(N-1)]
graph = [{} for _ in range(N)]
for src, dst in edges:
    graph[src][dst] = 1
    graph[dst][src] = 1
graph[X-1][Y-1] = 1
graph[Y-1][X-1] = 1

import collections
d_frq_dict = collections.Counter()
for start in range(N):
    dist = [float('inf') for _ in range(N)]
    dist[start] = 0
    buf = [start]
    while buf:
        src = buf.pop(0)
        for dst in graph[src]:
            if dist[dst] == float('inf'):
                dist[dst] = dist[src] + 1
                buf.append(dst)

    d_frq_dict.update(dist)
    # print(dist)

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

Submission status: Accepted

Solution code:
n, x, y = 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)

Submission status: Accepted

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

def main():
    ans = {}
    for i in range(1, n):
        ans[i] = 0

    for i in range(0, n - 1):
        for j in range(i + 1, n):
            ans[solve(i, j)] += 1

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

def solve(i, j):
    """
    最短距離を計算する
    O(1)
    """

    dist = min(abs(i - j), abs(x - i) + abs(y - j) + 1, abs(y  -i) + abs(x - j) + 1)

    return dist

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
n,x,y=map(int,input().split())
lst=[]
num=[0]*(n+1)
for i in range(1,n):
  for j in range(i+1,n+1):
    k=min(abs(i-j),abs(i-x)+1+abs(j-y),abs(i-y)+1+abs(j-x))
    if num[k]==0:
      num[k]+=1
    lst.append(k)
    
Lst=list(collections.Counter(lst).items())
key=0
for i in range(1,n):
  if num[i]==0:
    print(0)
  else:
    print(Lst[key][1])
    key+=1

Submission status: Accepted

Solution code:
def main():
    N, X, Y = map(int, input().split())
    count_list = [0] * N
    for i in range(1, N):
        for j in range(i + 1, N + 1):
            distance = min(j-i, abs(j-Y) + abs(i-X) + 1)
            count_list[distance] += 1
    
    for i in range(1, N):
        print(count_list[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = [0] * N
 
for i in range(N-1):
  for j in range(i+1, N):
    d = min(j-i, abs(i-X) + abs(j-Y) + 1)
    ans[d] += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0] * N

for i in range(1,N):
    for j in reversed(range(N+1)):
        if i >= j:
            break

        tmp = min(j-i,abs(X-i)+1+abs(Y-j))
        ans[tmp] += 1

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

Submission status: Accepted

Solution code:

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

pat = [0]*(N-1)

for i in range(N):
  for j in range(i+1, N):
    d = min(abs(i-j), abs(X-i)+1+abs(j-Y))
    pat[d-1] += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#６回目、2020-0612
#2重ループ　＋O(1)
#場合分けを近道と通常のみ（絶対値を使う）

#初期入力
N, x, y = map(int, input().split())
normal =0
short =0
ans ={i:0 for i in range(1,N)}
for i in range(1,N):
    for j in range(i+1,N+1):
         normal =j -i
         short  =abs(x-i) +1 +abs(j-y)
         dist =min(normal,short)
         ans[dist] +=1
      

#答え出力
for i in range(1,N):        
    print(ans[i])

Submission status: Accepted

Solution code:
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
n, x, y = [int(x) for x in input().split()]
ans = [0 for k in range(n)]
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        ans[min(abs(i - j), abs(x - i) + 1 + abs(y - j), abs(y - i) + 1 + abs(x - j))] += 1
print(*(ans[1:]), sep='\n')

Submission status: Accepted

Solution code:
#６回目、2020-0612
#2重ループ　＋O(1)
#i,jがループの中か外で場合分け

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

ans ={i:0 for i in range(1,N)}
for i in range(1,N):
    for j in range(i+1,N+1):
         #（i,jがループより共に左、ともに右）
        if (j <=x or y <=i) :
            ans[j-i] +=1
        # （iがループより左 and jがループより右）
        elif i <=x and y <=j:
            ans[x-i +1 +j-y] +=1
        # i,jが共にループの中
        elif x <i and j <y:
            dist =min(j-i,i-x + y-j +1) #時計回りと反時計回りの短いほう、+1はxとyを結んだ部分
            ans[dist] +=1
        # iがループより左、jがループの中
        elif i <=x and j < y:
            dist =x-i + min(j-x , y+1-j)
            ans[dist] +=1 
        # iがループの中、jがループの右
        elif x <i and y <=j:
            dist =min(y-i , 1 +i-x) + j-y
            ans[dist] +=1 

#答え出力
for i in range(1,N):        
    print(ans[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x,y = map(int,input().split())
k = [0]*(n)

for i in range(1,n):
  for j in range(i+1,n+1):
    if i < x and j <= x:
      k[j-i] += 1
    elif i >= y and j > y:
      k[j-i] += 1
    elif x <= i < y and x< j <= y:
      ind = min(j-i,i-x+y-j+1)
      k[ind] += 1
    elif i < x and x < j <= y:
      ind = min(j-i,x-i+y-j+1)
      k[ind] += 1
    elif x <= i < y and y < j:
      ind = min(j-i,i-x+1+j-y)
      k[ind] += 1
    elif i< x and j > y:
      ind = x - i + 1 + j - y
      k[ind] += 1
      
for i in range(1,n):
  print(k[i])

Submission status: Accepted

Solution code:
n,x,y = map(int,input().split())
k = [0]*(n)

for i in range(1,n):
  for j in range(i+1,n+1):
    if i < x and j <= x:
      k[j-i] += 1
    elif i >= y and j > y:
      k[j-i] += 1
    elif x <= i < y and x<j<=y:
      ind = min(j-i,abs((i-x))+abs((y-j))+1)
      k[ind] += 1
    elif i < x and x<j<=y:
      ind = min(j-i,abs((x-i))+abs((y-j))+1)
      k[ind] += 1
    elif x<=i<y and y<j:
      ind = min(j-i,abs((i-x))+1+abs((j-y)))
      k[ind] += 1
    elif i< x and j > y:
      ind = (x-i) + 1 + (j-y)
      k[ind] += 1
      
for i in range(1,n):
  print(k[i])

Submission status: Accepted

Solution code:
# D - Line++
N,X,Y = map(int,input().split())
k = [0]*N
for i in range(1,N):
    for j in range(i+1,N+1):
        t = min(j-i, abs(i-X)+1+abs(j-Y))
        k[t] += 1
for i in range(1,N):
    print(k[i])

Submission status: Accepted

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):
        t = min(abs(j-i), abs(x-i)+1+abs(y-j))
        ans[t-1] += 1

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
n, x, y = 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])

Submission status: Accepted

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

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

for a in ans:
  print(a)

Submission status: Accepted

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

def main():
    N,X,Y = map(int,input().split())
    edge = [[] for _ in range(N)]
    for i in range(N):
        if i == 0:
            edge[i].append(i+1)
        elif i == N-1:
            edge[i].append(i-1)
        else:
            edge[i].append(i-1)
            edge[i].append(i+1)
    edge[X-1].append(Y-1)
    edge[Y-1].append(X-1)
    
    ans = [0]*(N-1)
    
    for i in range(N):
        visited = [0]*N
        dist = [0]*N
        q = deque([i])#i番目のノードを根とする探索
        visited[i] = 1
        while q:
            now = q.popleft()
            for connection in edge[now]:
                if visited[connection]:
                    dist[connection] = min(dist[connection],dist[now]+1)
                else:
                    visited[connection] = 1
                    dist[connection] = dist[now] + 1
                    q.append(connection)
        for d in dist:
            if d == 0:
                continue
            ans[d-1] += 1
    ans = list(map(lambda x: x//2,ans))
    print(*ans,sep="\n")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def bfs(root):
        dist = [f_inf] * n
        dist[root] = 0
        que = deque()
        que.append(root)
        while que:
            prev = que.popleft()
            for next in tree[prev]:
                if dist[next] == f_inf:
                    dist[next] = dist[prev] + 1
                    que.append(next)
        return dist

    n, x, y = map(int, input().split())
    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)

    cnt = [0] * n
    for i in range(n):
        dist = bfs(i)
        for d in dist:
            cnt[d] += 1

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

    for v in distances[1:]:
        print(v)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import combinations as cb
n,x,y = map(int, input().split())
pair = list(cb(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])

Submission status: Accepted

Solution code:
from itertools import combinations as cb
node = []
n,x,y = 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])

Submission status: Accepted

Solution code:
import itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

combi = list(itertools.combinations(range(1,N+1),2))

ansList = [0 for _ in range(N)]

for i,j in combi:
    kyori = min(j-i, abs(j-Y) + abs(X-i) + 1)
    ansList[kyori] += 1
#    print(i,j,ansList)

for ans in ansList[1:]:
    print(ans)

Submission status: Accepted

Solution code:
import itertools

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

combi = list(itertools.combinations(range(1,N+1),2))

ansList = [0 for _ in range(N)]

for i,j in combi:
    kyori = min(j-i, abs(j-Y) + abs(X-i) + 1)
    ansList[kyori] += 1
#    print(i,j,ansList)

for ans in ansList[1:]:
    print(ans)

Submission status: Accepted

Solution code:
import sys

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

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

result = [0 for i in range(n)]
for i in range(n):
    for j in range(n):
        if i == j :
            continue
        k = calc(i, j, x, y)       
        result[k] += 1

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

Submission status: Accepted

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

c=min(x,y)-1
d=max(x,y)-1

e=[0]*n

for i in range(n):
    for j in range(i+1,n):
        a=j-i
        if i<c and d<j:
            b=c-i+j-d+1
        elif c<=i and d<j:
            b=i-c+j-d+1
        elif i<c and j<=d:
            b=c-i+d-j+1
        elif c<=i and j<=d:
            b=i-c+d-j+1
        t=min(a,b)
        #print(i,j,t)
        e[t]+=1
for f in e[1:]:
    print(f)

Submission status: Accepted

Solution code:
from collections import defaultdict
N,X,Y = map(int,input().split())

counter = defaultdict(int)
for i in range(1,N):
  for j in range(i+1, N+1):
    step = min(j-i, abs(X-i)+1+abs(Y-j))
    counter[step] += 1

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

Submission status: Accepted

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

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

for c in cnt:
    print(c)