結果

問題 No.2064 Smallest Sequence on Grid
ユーザー ntudantuda
提出日時 2022-09-30 14:38:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 816 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 86,348 KB
実行使用メモリ 119,688 KB
最終ジャッジ日時 2023-08-24 05:22:13
合計ジャッジ時間 9,483 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
75,076 KB
testcase_01 AC 75 ms
71,144 KB
testcase_02 AC 76 ms
70,944 KB
testcase_03 AC 76 ms
71,032 KB
testcase_04 AC 76 ms
70,812 KB
testcase_05 AC 75 ms
70,892 KB
testcase_06 AC 75 ms
70,868 KB
testcase_07 AC 75 ms
70,708 KB
testcase_08 AC 74 ms
70,944 KB
testcase_09 AC 75 ms
70,836 KB
testcase_10 AC 79 ms
70,692 KB
testcase_11 AC 80 ms
70,976 KB
testcase_12 AC 81 ms
70,876 KB
testcase_13 AC 98 ms
75,804 KB
testcase_14 AC 113 ms
77,068 KB
testcase_15 AC 110 ms
77,020 KB
testcase_16 AC 115 ms
76,864 KB
testcase_17 AC 185 ms
86,720 KB
testcase_18 AC 179 ms
86,644 KB
testcase_19 AC 186 ms
86,672 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 = [(0, 0)]
for _ in range(H + W - 2):
    # 次の候補の座標をQ2に追加
    # 重複するけど気にしない
    Q2 = []
    h0 = -1
    for h, w in Q:
        if w < W - 1 and h > h0:
            heappush(Q2,(S[h][w + 1], h, w + 1))
            h0 = h
        if h < H - 1 and h + 1 > h0:
            heappush(Q2,(S[h + 1][w], h + 1, w))
            h0 = h + 1
    # Qを空にしてから文字が最小の物だけ抽出してQに追加
    Q = []
    c,h,w = heappop(Q2)
    c0 = c
    T.append(c)
    #print("Q2",Q2)
    while c == c0:
        Q.append((h, w))
        if len(Q2) == 0:
            break
        c,h,w = heappop(Q2)
    Q.sort()
    #print("Q",Q)

print("".join(T))
0