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: Time Limit Exceeded

Solution code:
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,x,y=n1()

a=[]
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if i<=x and j<=x:
            a.append([(i,j),j-i])
        elif i<=x and x<j<y:
            a.append([(i,j),min(j-i,y-j+1+x-i)])
        elif i<=x:
            a.append([(i,j),j-y+1+x-i])
        elif i<=y and j<=y:
            a.append([(i,j),min(j-i,y-j+1+i-x)])
        elif i<=y:
            a.append([(i,j),min(j-i,j-y+1+i-x)])
        else:
            a.append([(i,j),j-i])
for k in range(1,n):
    ans=0
    for h in range(len(a)):
        if a[h][1]==k:
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd
import heapq
import queue
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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


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

    edge = [[] for i in range(N)]
    #edge[i] : iから出る道の[重み,行先]の配列
    for i in range(N-1):
        edge[i].append([1,i+1])
        edge[i+1].append([1,i])
    edge[X-1].append([1,Y-1])
    edge[Y-1].append([1,X-1])
    
    res = [0] * N
    for j in range(N):
        for k in dijkstra_heap(j, N, edge):
            res[k] += 1     
    
    for l in range(1, N):
        print(res[l] // 2)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n ,x, y = map(int, input().split())
'''
degree_all = []
d = [float('inf')]*n
for i in range(n):
    degree_all.append(d)
for i in range(n-1):
    degree_all[i][i] = 0
    if i != n-1:
        degree_all[i][i+1] = 1
        #degree_all[i+1][i] = 1
'''
sub_degree = [0]*n
for i in range(n):
    for j in range(i+1, n):
        sub_degree[min(abs(j-i), abs(x-1-i)+1+abs(j-y+1), abs(y-1-i)+1+abs(j-x+1))-1]+=1
'''
for i in range(n-1):
    for j in range(i+1, n):
        sub_degree[degree_all[i][j]-1] +=1
        #print(degree_all[i][j])
#print("aaaa")
'''
for i in range(n-1):
    print(sub_degree[i])

Submission status: Time Limit Exceeded

Solution code:
n ,x, y = map(int, input().split())
degree_all = []
d = [float('inf')]*n
for i in range(n):
    degree_all.append(d)
for i in range(n):
    degree_all[i][i] = 0
    if i != n-1:
        degree_all[i][i+1] = 1
        #degree_all[i+1][i] = 1
sub_degree = [0]*n
for i in range(n):
    for j in range(i+1, n):
        sub_degree[min(abs(j-i), abs(x-1-i)+1+abs(j-y+1), abs(y-1-i)+1+abs(j-x+1))-1]+=1
'''
for i in range(n-1):
    for j in range(i+1, n):
        sub_degree[degree_all[i][j]-1] +=1
        #print(degree_all[i][j])
#print("aaaa")
'''
for i in range(n-1):
    print(sub_degree[i])

Submission status: Time Limit Exceeded

Solution code:
n ,x, y = map(int, input().split())
degree_all = []
for i in range(n):
    degree_all.append([float('inf')]*n)
for i in range(n):
    degree_all[i][i] = 0
    if i != n-1:
        degree_all[i][i+1] = 1
        degree_all[i+1][i] = 1

for i in range(n):
    for j in range(i+1, n):
        degree_all[i][j] = min(abs(j-i), abs(x-1-i)+1+abs(j-y+1), abs(y-1-i)+1+abs(j-x+1))
sub_degree = [0]*n
for i in range(n-1):
    for j in range(i+1, n):
        sub_degree[degree_all[i][j]-1] +=1
        #print(degree_all[i][j])
#print("aaaa")
for i in range(n-1):
    print(sub_degree[i])

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from queue import Queue
 
 
def main():
    n, x, y = [int(x) for x in stdin.readline().rstrip().split()]
    x -= 1
    y -= 1
    ans = [0] * n
    for i in range(n):
        dist = [None] * n
        q = Queue()
 
        def push(d, v):
            if v < 0 or n <= v:
                return
            if dist[v] is not None:
                return
            dist[v] = d
            q.put(v)
 
        push(0, i)
        while not q.empty():
            v = q.get()
            d = dist[v]
            push(d + 1, v - 1)
            push(d + 1, v + 1)
            if v == x:
                push(d + 1, y)
            if v == y:
                push(d + 1, x)
 
        for d in dist:
            ans[d] += 1
 
    ans = [x // 2 for x in ans]
    print(*ans[1:], sep='\n')
 
 
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n,x,y=map(int,input().split())
x-=1
y-=1
ans=[0 for i in range(n)]
for ni in range(n):
    d=[100000 for i in range(n)]
    q=[]
    q.append(ni)
    d[ni]=0
    while q:
        p=q.pop()
        if(p>0 and d[p-1]>d[p]+1):
            q.append(p-1)
            d[p-1]=d[p]+1
        if(p<n-1 and d[p+1]>d[p]+1):
            q.append(p+1)
            d[p+1]=d[p]+1

        if(p==x and d[y]>d[x]+1):
            q.append(y)
            d[y]=d[x]+1
        if(p==y and d[x]>d[y]+1):
            q.append(x)
            d[x]=d[y]+1

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

Submission status: Time Limit Exceeded

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

for i in range(1,N):
    	print(List.count(i))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


def func(i, j) -> int:
    a = abs(j - i)
    b = abs(i-x)+1+abs(j-y)
    c = abs(i - y) + 1 + abs(j - x)
    return min(a, b, c)


hoge = [0] * (N - 1)
for k in range(1, N-1):
    for i in range(1, N + 1):
        for j in range(i, N + 1):
            if func(i, j) == k:
                hoge[k-1] += 1

for x in hoge:
    print(x)

Submission status: Time Limit Exceeded

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


def func(i, j) -> int:
    a = abs(j - i)
    b = abs(i-x)+1+abs(j-y)
    c = abs(i - y) + 1 + abs(j - x)
    return min(a, b, c)


for k in range(1, N):
    ans = 0
    for i in range(1, N + 1):
        for j in range(i, N + 1):
            if func(i, j) == k:
                ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    A = list(map(int,input().split()))
    N = A[0]
    X = A[1]
    Y = A[2]
    list1 = [[0 for i in range(N)] for j in range(N)]
    ans = [0 for i in range(N-1)]

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

    for i in ans:
        print(i)


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    A = list(map(int,input().split()))
    N = A[0]
    X = A[1]
    Y = A[2]
    list1 = [[0 for i in range(N)] for j in range(N)]
    ans = [0 for i in range(N-1)]

    for i in range(N):
        for j in range(N):
            if abs(i-j) == 1:
                list1[i][j] = 1
            elif i == X-1 and j == Y-1:
                list1[i][j] = 1
            elif i == Y-1 and j == X-1:
                list1[i][j] = 1
            else:
                list1[i][j] = N*2

    for l in range(N):
        for i in range(N):
            for j in range(N):
                list1[i][j] = min(list1[i][j], list1[i][l]+list1[l][j])

    for i in range(N):
        for j in range(i+1,N):
            if(list1[i][j] < N):
                ans[list1[i][j]-1] += 1

    for i in ans:
        print(i)


main()

Submission status: Time Limit Exceeded

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

for i in range(1,N):
    	print(List.count(i))

Submission status: Time Limit Exceeded

Solution code:
def abs(x):
    if x < 0:
        return -x;
    else:
        return x;

n, x, y = (int(i) for i in input().split());

x -= 1;
y -= 1;

cnt = [0 for k in range(n - 1)];

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

for i in cnt:
    print(i);

Submission status: Time Limit Exceeded

Solution code:
import math

n, x, y = (int(i) for i in input().split());

x -= 1;
y -= 1;

cnt = [0 for k in range(n - 1)];

for i in range(n):
    for j in range(i + 1, n):
        p = j - i;
        p = min(p, math.fabs(x - i) + 1 + math.fabs(y - j));
        p = min(p, math.fabs(y - i) + 1 + math.fabs(x - j));
        cnt[int(p) - 1] += 1;

for i in cnt:
    print(i);

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


def main():
    N, X, Y = tuple(map(int, input().split()))

    def distance(i, j):
        return min(abs(i - j), abs(X - i) + abs(Y - j) + 1, abs(X - j) + abs(Y - i) + 1)

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

    for k in range(1, N):
        print(distances.count(k))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,x,y=map(int, input().split())
x -= 1
y -= 1
queue = []
zumi = []
result = [[0]* n for i in range(n)]
next_point = []

for i in range(n):
    queue.append(i)
    zumi = []
    result[i][i] = 0
    
    while queue:
        next_point = []
        now = queue.pop(0)
        zumi.append(now)
        
        #次に行ける場所
        if now - 1 >= 0:
            next_point.append(now - 1)
        if now + 1 < n :
            next_point.append(now +1)
        if now == x:
            next_point.append(y)
        if now == y:
            next_point.append(x)
            
        for a in next_point:
            if a in zumi :
                pass
            elif result[i][a] == 0:
                result[i][a] = result[i][now] + 1
                queue.append(a)
                
for i in range(1,n):
    count = 0
    for j in result:
        count += j.count(i)
    print(int(count/2))

Submission status: Time Limit Exceeded

Solution code:
def min_dist(i, j, X, Y):
    return min(abs(j-i), abs(X-1-i)+1+abs(Y-1-j), abs(Y-1-i)+1+abs(X-1-j))

N, X, Y = list(map(int, input().split()))
pairs = [[i, j] for i in range(N-1) for j in range(i+1, N)]
dists = [min_dist(x[0], x[1], X, Y) for x in pairs]
for K in range(1,N):
    print(len([x for x in dists if x == K]))

Submission status: Time Limit Exceeded

Solution code:
def min_dist(i, j, X, Y):
    return min(abs(j-i), abs(X-1-i)+1+abs(Y-1-j), abs(Y-1-i)+1+abs(X-1-j))

N, X, Y = list(map(int, input().split()))
pairs = [[i, j] for i in range(N-1) for j in range(i+1, N)]
for K in range(1,N):
    print(len([x for x in pairs if min_dist(x[0], x[1], X, Y) == K]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

x-=1
y-=1
ans=[0 for i in range(n)]
for i in range(n):
    d=[100000 for i in range(n)]
    d[i]=0
    q=[]
    q.append(i)
    while q:
        p=q.pop()
        if(p-1>=0 and d[p]+1<d[p-1]):
            q.append(p-1)
            d[p-1]=d[p]+1
        if(p+1<n and d[p]+1<d[p+1]):
            q.append(p+1)
            d[p+1]=d[p]+1

        if(p==x and d[x]+1<d[y]):
            q.append(y)
            d[y]=d[x]+1
        if(p==y and d[y]+1<d[x]):
            q.append(x)
            d[x]=d[y]+1

    for j in range(n):ans[d[j]]+=1


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

Submission status: Time Limit Exceeded

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

x-=1
y-=1
ans=[]
for i in range(n):
    d=[100000 for i in range(n)]
    d[i]=0
    q=[]
    q.append(i)
    while q:
        p=q.pop()
        if(p-1>=0 and d[p]+1<d[p-1]):
            q.append(p-1)
            d[p-1]=d[p]+1
        if(p+1<n and d[p]+1<d[p+1]):
            q.append(p+1)
            d[p+1]=d[p]+1

        if(p==x and d[x]+1<d[y]):
            q.append(y)
            d[y]=d[x]+1
        if(p==y and d[y]+1<d[x]):
            q.append(x)
            d[x]=d[y]+1

    ans.append(d)

ans2=[0 for i in range(n-1)]
for i in ans:
    for j in range(n-1):
        ans2[j]+=i.count(j+1)
for i in ans2:
    print(i//2)

Submission status: Time Limit Exceeded

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

x-=1
y-=1
ans=[0 for i in range(n)]
for i in range(n):
    d=[100000 for i in range(n)]
    d[i]=0
    q=[]
    q.append(i)
    while q:
        p=q.pop()
        if(p-1>=0 and d[p]+1<d[p-1]):
            q.append(p-1)
            d[p-1]=d[p]+1
        if(p+1<n and d[p]+1<d[p+1]):
            q.append(p+1)
            d[p+1]=d[p]+1

        if(p==x and d[x]+1<d[y]):
            q.append(y)
            d[y]=d[x]+1
        if(p==y and d[y]+1<d[x]):
            q.append(x)
            d[x]=d[y]+1

    for j in range(1,n):
        ans[j]+=d.count(j)

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

Submission status: Time Limit Exceeded

Solution code:
N,X,Y = map(int, input().split())
answer= [0]*(N-1)
for i in range(1,N+1):
    for j in range(1,N+1):
        if i==j:
            break
        ans=N-1
        if i-j<ans:
            ans=i-j
        if j<=X and i<=Y and i>=X:
            if Y-i+1+X-j<ans:
                ans=Y-i+1+X-j
        if j<=X and i>=Y:
            if i-Y+1+X-j<ans:
                ans=i-Y+1+X-j
        if j>=X and j<=Y and i>=Y:
            if i-Y+1+j-X<ans:
                ans=i-Y+1+j-X
        if j>=X and j<=Y and i>=X and i<=Y:
          if Y-i+1+j-X<ans:
            ans=Y-i+1+j-X
        answer[ans-1]=answer[ans-1]+1

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter, deque, defaultdict

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

v = defaultdict(list)
for i in range(n):
    if i + 1 < n: v[i].append(i + 1)
    if i - 1 >= 0: v[i].append(i - 1)
v[x - 1].append(y - 1)
v[y - 1].append(x - 1)

cnt = Counter()
for start in range(n):
    dist = [float("inf")] * n
    q = deque()
    q.append([start, 0])
    while q:
        c, d = q.popleft()
        for next in v[c]:
            if dist[next] == float("inf"):
                q.append([next, d + 1])
                dist[next] = d + 1
    cnt += Counter(dist[start + 1:])

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,X,Y = map(int, input().split())
cnt = np.zeros(N+1)
for i in range(1,N+1):
    for j in range(i+1,N+1):
        if abs(X-i)+abs(j-Y)+1 < j-i:
            cnt[abs(X-i)+abs(j-Y)+1] += 1
        else:
            cnt[j-i] += 1
for i in range(1,N):
    print(int(cnt[i]))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3

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

cs = [0 for i in range(n)]

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

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

Submission status: Time Limit Exceeded

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):
      ans[min(abs(j-i), abs(X-i-1) + 1 + abs(j+1-Y ), abs(Y-i-1) + 1 + abs(j+1-X))-1]+=1
for i in range(N-1):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())

ansN = 0
count_list = [0] * sum([i for i in range(1,n + 1)])

cnt = 0

for i in range(1,n):
  for k in range(i+1,n+1):
    a0 = k-i
    a1 = abs(a-i)+ abs(b-k) + 1
    
    count_list[cnt] = min(a0,a1)
    cnt += 1
    
for result in range(1,n):
  print(count_list.count(result))

Submission status: Time Limit Exceeded

Solution code:
#node edge , s , e
n,a,b = map(int,input().split())
#count

ansN = 0
count_list = [0] * sum([i for i in range(1,n + 1)])

#count_listのindex
cnt = 0

#start
for i in range(1,n):
  #stop
  for k in range(i+1,n+1):
    #tyokusen
    a0 = k-i
    #tikamichi
    a1 = abs(a-i)+ abs(b-k) + 1
    
    count_list[cnt] = min(a0,a1)
    #print(i,"@",k,"@",count_list,cnt)
    cnt += 1
    
for result in range(1,n):
  print(count_list.count(result))

Submission status: Time Limit Exceeded

Solution code:
#D
from collections import deque
N,X,Y = map(int,input().split())
dist = [0 for _ in range(N)]

for i in range(N):
    s = i+1
    sdist = [-1 for _ in range(N)]
    d = deque([])
    d.append([s,0])
    while d:
        x,n = d.popleft()
        if sdist[x-1] == -1:
            sdist[x-1] = n
            
            if x < N:
                d.append([x+1,n+1])
            if x > 1:
                d.append([x-1,n+1])
            if x == X:
                d.append([Y,n+1])
            if x == Y:
                d.append([X,n+1])
    
    for sd in sdist:
        dist[sd]+=1
        
for i in range(N-1):
    print(dist[i+1]//2)

Submission status: Time Limit Exceeded

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

def d(i, j, X, Y):
  return min((j - i), abs(X - i) + abs(Y - j) + 1)

l = sum([[d(i, j, X, Y) for j in range(1, N+1) if i < j] for i in range(1, N+1)], [])

for x in range(1, N):
  c = l.count(x)
  print(c)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# coding: utf-8
# import pprint
# import numpy as np
# import code
import functools

def debug(arg):
    if __debug__:
        pass
    else:
        import sys
        debug = lambda *x: None
        print(arg, file=sys.stderr)

n, x, y = (int(x) for x in input().split())
d = dict.fromkeys(range(1, n), 0)
debug(d)
for i in range(1, n):
    for j in range(i + 1, n + 1):
        debug([i, j, x, y])
        dd1=abs(x - i) + 1 + abs(y - j)
        dd2= j - i
        d[min(dd1, dd2)] += 1
        debug(d)

for n in d.values():
    print(n)

Submission status: Time Limit Exceeded

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

X -= 1
Y -= 1

q = deque()

ans = [0] * N

def BFS(x, cnt):
    if dist[x] != (N + 1):
        return
    cnt += 1
        
    dist[x] = cnt
    if x + 1 < N:
        q.append((x + 1, cnt))
    if x - 1 >= 0:
        q.append((x - 1, cnt))
    if x == X:
        q.append((Y, cnt))
    if x == Y:
        q.append((X, cnt))


for x in range(N):
    dist = [N + 1] * N
    q.append((x, -1))
    while q:
        BFS(*q.popleft())

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

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

Submission status: Time Limit Exceeded

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

X -= 1
Y -= 1

q = Queue()

ans = [0] * N

def BFS(x, cnt):
    if dist[x] != (N + 1):
        return
    cnt += 1
        
    dist[x] = cnt
    if x + 1 < N:
        q.put((x + 1, cnt))
    if x - 1 >= 0:
        q.put((x - 1, cnt))
    if x == X:
        q.put((Y, cnt))
    if x == Y:
        q.put((X, cnt))


for x in range(N):
    dist = [N + 1] * N
    q.put((x, -1))
    while not q.empty():
        BFS(*q.get())

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

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# coding: utf-8
# import pprint
# import numpy as np
# import code
import functools

def debug(arg):
    if __debug__:
        pass
    else:
        import sys
        debug = lambda *x: None
        print(arg, file=sys.stderr)

n, x, y = (int(x) for x in input().split())
d = dict.fromkeys(range(1, n), 0)
debug(d)
for i in range(1, n):
    for j in range(i + 1, n + 1):
        debug([i, j, x, y])
        dd1=abs(x - i) + 1 + abs(y - j)
        dd2= j - i
        d[min(dd1, dd2)] += 1
        debug(d)

for k in sorted(d.keys()):
    print(d[k])

Submission status: Time Limit Exceeded

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

X -= 1
Y -= 1

q = Queue()

ans = [0] * N

def BFS(x, cnt):
    if dist[x] != (N + 1):
        return
    cnt += 1
        
    dist[x] = cnt
    for n in range(N):
        if n == (x + 1):
            q.put((n, cnt))

        elif n == (x - 1):
            q.put((n, cnt))

        elif (x == X) and (n == Y):
            q.put((n, cnt))

        elif (x == Y) and (n == X):
            q.put((n, cnt))


for x in range(N):
    dist = [N + 1] * N
    q.put((x, -1))
    while not q.empty():
        BFS(*q.get())

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

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

Submission status: Time Limit Exceeded

Solution code:
x = list(map(int,input().split()))
N = x[0]
X = x[1]
Y = x[2]

import numpy as np
ans = np.zeros(N)

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

[print(int(x)) for x in ans[1:]]

Submission status: Time Limit Exceeded

Solution code:
x = list(map(int,input().split()))
N = x[0]
X = x[1]
Y = x[2]

import numpy as np
ans = np.zeros(N)
for i in range(1,N+1):
    for j in range(i,N+1):
        k = min(abs(i-j),abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X))
        ans[k] += 1

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

Submission status: Time Limit Exceeded

Solution code:

def D_160():
    N, X, Y = map(int, input().split())
    count_list = [[0]*N for i in range(N)]
    for i in range(0,N):
        for j in range(i,N):
            count_list[i][j] = min(j-i,abs(X-1-i) + abs(j-(Y-1)) + 1)
    
    #print(count_list)
    count_list = sum(count_list,[])
    
    for i in range(1,N):
        print(count_list.count(i))

D_160()

Submission status: Time Limit Exceeded

Solution code:
def D_160():
    import itertools
    import collections
    N, X, Y = map(int, input().split())
    count_list = [[0]*N for i in range(N)]
    for i in range(0,N):
        for j in range(i,N):
            count_list[i][j] = min(j-i,abs(X-1-i) + abs(j-(Y-1)) + 1)
    
   # print(count_list)
    count_list = sum(count_list,[])
    
    for i in range(1,N):
        print(count_list.count(i))

D_160()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

n, x, y = [int(x) for x in input().split()]
x -= 1
y -= 1

# グラフを陽に持つ。
edges = [[] for _ in range(n)]
for i, e in enumerate(edges):
    if i == y:
        e.append(x)
    if i > 0:
        e.append(i - 1)
    if i < n - 1:
        e.append(i + 1)
    if i == x:
        e.append(y)

ans = [0] * n  # Patterns by distances

for v in range(n):
    que = deque()  # Queue
    que_append = que.append
    que_popleft = que.popleft
    dist = [-1] * n  # Distance

    dist[v] = 0
    que_append(v)

    while len(que):
        new_v = que_popleft()

        for adjacent in edges[new_v]:
            if dist[adjacent] != -1:
                continue
            que_append(adjacent)
            dist[adjacent] = dist[new_v] + 1

    for d in dist:
        ans[d] += 1

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

Submission status: Time Limit Exceeded

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

d=[[-1 for i in range(n)] for j in range(n)]
for i in range(n):
  d[i][i]=0
num=[0 for i in range(n)]
g=[[i+1] for i in range(n-1)]
g.append([])
for i in range(1,n):
  g[i].append(i-1)
x-=1
y-=1
g[x].append(y)
g[y].append(x)

def bfs(start):
  #global d
  #global g
  q=[start]
  while q:
    now=q.pop(0)
    #print("now",now,"q",q,"d",d)
    for i in g[now]:
      if d[start][i]!=-1:
        continue
      else:
        d[start][i]=d[start][now]+1
        q.append(i)
 
for i in range(n):
  bfs(i)

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

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

Submission status: Time Limit Exceeded

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

d=[[-1 for i in range(n)] for j in range(n)]
for i in range(n):
  d[i][i]=0
num=[0 for i in range(n)]
g=[[i+1] for i in range(n-1)]
g.append([])
for i in range(1,n):
  g[i].append(i-1)
x-=1
y-=1
g[x].append(y)
g[y].append(x)

def bfs(start,dist=0):
  #global d
  #global g
  q=[start]
  while q:

    dist+=1
    now=q.pop(0)
    #print("now",now,"q",q,"d",d)
    for i in g[now]:
      if d[start][i]!=-1:
        continue
      else:
        d[start][i]=d[start][now]+1
        q.append(i)
 
for i in range(n):
  bfs(i)

for i in range(n-1):
  for j in range(i+1,n):
    if d[i][j]>=n:
      continue
    num[d[i][j]]+=1

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

Submission status: Time Limit Exceeded

Solution code:
n, x, y = map(int, input().split())
lengths = [min(end - start, abs(x-start) + abs(y-end) + 1)
    for start in range(1, n+1)
        for end in range(start+1, n+1)]
for k in range(1, n):
    print(lengths.count(k))

Submission status: Time Limit Exceeded

Solution code:
n, x, y = map(int, input().split())
for k in range(1, n):
    count = 0
    for start in range(1, n+1):
        for end in range(start+1, n+1):
            if min(end - start, abs(x-start) + abs(y-end) + 1) == k:
                count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n, x, y = map(int,
              input().split())
ans = [0] * (n-1)
for i in range(1,n+1):
    for j in range(1, n+1):
        if i != j:
            diff = min(abs(i-j), abs(i-x)+1+abs(j-y), abs(i-y)+1+abs(j-x))
            ans[diff-1] += 1
for i in ans: # 入れ替えてもペアは同じ
    print(i//2)

Submission status: Time Limit Exceeded

Solution code:
N, X, Y = map(int, input().split())
dist_list = []*N

for i in range(N):
    for j in range(i+1, N):
        a = j - i
        b = abs(i+1 - X) + abs(j+1 -Y) + 1
        if a > b:
            dist_list.append(b)
        else:
            dist_list.append(a)

for k in range(N-1):
    print(dist_list.count(k+1))

Submission status: Time Limit Exceeded

Solution code:
[N, X, Y] = input().split()
N = int(N)
X = int(X)
Y = int(Y)
dist_list = []

for i in range(N):
    for j in range(i+1, N):
        a = j - i
        b = abs(i+1 - X) + abs(j+1 -Y) + 1
        if a > b:
            dist_list.append(b)
        else:
            dist_list.append(a)

for k in range(N-1):
    print(dist_list.count(k+1))

Submission status: Time Limit Exceeded

Solution code:
[N, X, Y] = input().split()
N = int(N)
X = int(X)
Y = int(Y)
dist_list = []

for i in range(N):
    for j in range(i+1, N):
        a = j - i
        b = abs(i+1 - X) + abs(j+1 -Y) + 1
        dist_list.append(min(a, b))

for k in range(N-1):
    print(dist_list.count(k+1))