結果

問題 No.2064 Smallest Sequence on Grid
ユーザー ntudantuda
提出日時 2022-09-30 14:26:56
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 690 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 130,056 KB
最終ジャッジ日時 2023-08-24 05:20:44
合計ジャッジ時間 8,399 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
75,656 KB
testcase_01 AC 75 ms
71,364 KB
testcase_02 AC 74 ms
71,128 KB
testcase_03 AC 77 ms
71,232 KB
testcase_04 AC 75 ms
71,444 KB
testcase_05 AC 75 ms
71,360 KB
testcase_06 AC 77 ms
71,140 KB
testcase_07 AC 76 ms
71,128 KB
testcase_08 AC 76 ms
71,272 KB
testcase_09 AC 75 ms
71,448 KB
testcase_10 AC 78 ms
71,340 KB
testcase_11 AC 85 ms
75,628 KB
testcase_12 AC 88 ms
76,168 KB
testcase_13 AC 111 ms
78,132 KB
testcase_14 AC 135 ms
77,752 KB
testcase_15 AC 130 ms
77,788 KB
testcase_16 AC 132 ms
77,752 KB
testcase_17 AC 205 ms
87,804 KB
testcase_18 AC 182 ms
87,004 KB
testcase_19 AC 182 ms
87,812 KB
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)])
for _ in range(H + W - 2):
    # 次の候補の座標をQ2に追加
    # 重複するけど気にしない
    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