Problem p02726 (python)

Fixed submission:

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

# N = 2000
# X = 100
# Y = 1900


X -= 1
Y -= 1

# @profile


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

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


main(N, X, Y)

Buggy submission (verdict: Runtime Error):

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

# N = 2000
# X = 100
# Y = 1900
# X -= 1
# Y -= 1


# @profile
def main(N, X, Y):
    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:
            next_last_visited = []
            for v in last_visited:
                d = dist[v]
                if v+1 < N and dist[v+1] == float("inf"):
                    dist[v+1] = d+1
                    next_last_visited.append(v+1)
                if v-1 >= 0 and dist[v-1] == float("inf"):
                    dist[v-1] = d+1
                    next_last_visited.append(v-1)
                if v == X and dist[Y] == float("inf"):
                    dist[Y] = d+1
                    next_last_visited.append(Y)
                if v == Y and dist[X] == float("inf"):
                    dist[X] = d+1
                    next_last_visited.append(X)
            # print(last_visited, next_last_visited)
            last_visited = next_last_visited
        # print(dist)
        for d in dist:
            ans[d] += 1

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


main(N, X, Y)

Buggy submission (verdict: Runtime Error):
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)

Buggy submission (verdict: Runtime Error):
N, X, Y = list(map(int, input()))

import numpy as np
# N = 5
# X = 2
# Y = 4

dist = np.full(N*N, float("inf")).reshape((N, N))
np.fill_diagonal(dist, 0)
# np.fill_diagonal(dist[1:], 1)
np.fill_diagonal(dist[:, 1:], 1)
dist[X, Y] = 1
# dist[Y, X] = 1
for i in range(N):
    for j in range(i+1, N):
        for k in range(0, N):
            print(i, k, j, dist[i, k]+dist[k, j])
            dist[i, j] = min(dist[i, j], dist[i, k]+dist[k, j])
for i in range(1, N):
    count = np.count_nonzero(dist == i)
    print(count)