結果

問題 No.2673 A present from B
ユーザー miya145592miya145592
提出日時 2024-03-16 02:14:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 939 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 243,960 KB
最終ジャッジ日時 2024-03-16 02:15:06
合計ジャッジ時間 6,718 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,600 KB
testcase_01 AC 40 ms
55,600 KB
testcase_02 AC 42 ms
55,600 KB
testcase_03 AC 41 ms
55,600 KB
testcase_04 AC 59 ms
68,620 KB
testcase_05 AC 45 ms
55,600 KB
testcase_06 AC 695 ms
243,960 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 59 ms
66,392 KB
testcase_10 AC 59 ms
68,484 KB
testcase_11 AC 54 ms
66,404 KB
testcase_12 AC 223 ms
123,388 KB
testcase_13 WA -
testcase_14 AC 332 ms
154,436 KB
testcase_15 AC 160 ms
102,676 KB
testcase_16 AC 154 ms
101,760 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 64 ms
70,700 KB
testcase_20 AC 287 ms
139,772 KB
testcase_21 WA -
testcase_22 AC 41 ms
55,600 KB
testcase_23 WA -
testcase_24 AC 40 ms
55,600 KB
testcase_25 AC 40 ms
55,600 KB
testcase_26 AC 41 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))
        G[i*N+j+1].add((i*N+j, 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