結果

問題 No.2064 Smallest Sequence on Grid
ユーザー ntudantuda
提出日時 2022-09-30 14:24:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 687 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 89,108 KB
最終ジャッジ日時 2023-08-24 05:20:34
合計ジャッジ時間 11,126 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,224 KB
testcase_01 AC 75 ms
71,156 KB
testcase_02 AC 76 ms
70,896 KB
testcase_03 AC 75 ms
71,156 KB
testcase_04 AC 76 ms
70,880 KB
testcase_05 AC 75 ms
70,896 KB
testcase_06 AC 76 ms
70,820 KB
testcase_07 AC 73 ms
70,792 KB
testcase_08 AC 77 ms
70,980 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop

H, W = map(int, input().split())
S = [input() for _ in range(H)]
T = [S[0][0]]
Q = set([(0, 0)])
Q2 = []

for _ in range(H + W - 2):
    # 次の候補の座標をQ2に追加
    # 重複するけど気にしない
    for h, w in Q:
        if w < W - 1:
            heappush(Q2,(S[h][w + 1], h, w + 1))
        if h < H - 1:
            heappush(Q2,(S[h + 1][w], h + 1, w))
    # Qを空にしてから文字が最小の物だけ抽出してQに追加
    Q = set()
    c,h,w = heappop(Q2)
    c0 = c
    T.append(c)
    while c == c0:
        Q.add((h, w))
        if len(Q2) == 0:
            break
        c,h,w = heappop(Q2)

print("".join(T))
0