結果

問題 No.2673 A present from B
ユーザー miya145592miya145592
提出日時 2024-03-16 02:09:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 904 bytes
コンパイル時間 2,609 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 238,416 KB
最終ジャッジ日時 2024-03-16 02:09:41
合計ジャッジ時間 9,037 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,600 KB
testcase_01 AC 40 ms
55,600 KB
testcase_02 AC 39 ms
55,600 KB
testcase_03 AC 39 ms
55,600 KB
testcase_04 AC 69 ms
68,488 KB
testcase_05 AC 40 ms
55,600 KB
testcase_06 WA -
testcase_07 AC 613 ms
238,416 KB
testcase_08 AC 574 ms
238,416 KB
testcase_09 AC 51 ms
64,296 KB
testcase_10 AC 54 ms
66,388 KB
testcase_11 AC 52 ms
64,296 KB
testcase_12 AC 207 ms
121,596 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 150 ms
101,524 KB
testcase_16 AC 146 ms
100,736 KB
testcase_17 WA -
testcase_18 AC 157 ms
104,408 KB
testcase_19 AC 69 ms
70,576 KB
testcase_20 AC 257 ms
137,596 KB
testcase_21 AC 460 ms
201,572 KB
testcase_22 AC 41 ms
55,600 KB
testcase_23 WA -
testcase_24 AC 41 ms
55,600 KB
testcase_25 AC 40 ms
55,600 KB
testcase_26 AC 40 ms
55,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
L = (2*M+3)*N
G = [set() for _ in range(L)]
for i in range(N):
    for j in range(L//N-1):
        G[(j+1)*N+i].add((j*N+i, 0))
for i in range(1, 2*M+3, 2):
    for j in range(N-1):
        G[i*N+j].add((i*N+j+1, 1))
for i, a in enumerate(A):
    a-=1
    u = (i*2+2)*N+a
    v = (i*2+2)*N+a+1
    G[u].add((v-N, 0))
    G[v].add((u-N, 0))
    G[u].discard((u-N, 0))
    G[v].discard((v-N, 0))
#print(G)
deq = deque()
st = (2*M+2)*N
deq.append(st)
INF = 10**9
dist = [INF for _ in range(L)]
dist[st] = 0
while deq:
    v = deq.popleft()
    for nv, cost in G[v]:
        if dist[nv]!=INF:
            continue
        dist[nv] = dist[v] + cost
        if cost==0:
            deq.appendleft(nv)
        else:
            deq.append(nv)
#print(dist)
print(*dist[1:N])
0