結果

問題 No.2064 Smallest Sequence on Grid
ユーザー ntudantuda
提出日時 2022-10-01 17:06:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 445 ms / 3,000 ms
コード長 685 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 91,512 KB
最終ジャッジ日時 2023-08-25 14:49:23
合計ジャッジ時間 11,024 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,232 KB
testcase_01 AC 69 ms
71,472 KB
testcase_02 AC 68 ms
71,244 KB
testcase_03 AC 69 ms
71,240 KB
testcase_04 AC 68 ms
71,340 KB
testcase_05 AC 69 ms
71,148 KB
testcase_06 AC 70 ms
71,548 KB
testcase_07 AC 69 ms
71,504 KB
testcase_08 AC 70 ms
71,136 KB
testcase_09 AC 68 ms
71,332 KB
testcase_10 AC 70 ms
71,488 KB
testcase_11 AC 72 ms
71,328 KB
testcase_12 AC 71 ms
71,292 KB
testcase_13 AC 76 ms
76,112 KB
testcase_14 AC 75 ms
76,008 KB
testcase_15 AC 76 ms
75,984 KB
testcase_16 AC 75 ms
76,236 KB
testcase_17 AC 140 ms
85,588 KB
testcase_18 AC 138 ms
85,624 KB
testcase_19 AC 140 ms
85,668 KB
testcase_20 AC 398 ms
89,556 KB
testcase_21 AC 445 ms
89,920 KB
testcase_22 AC 290 ms
88,004 KB
testcase_23 AC 290 ms
89,272 KB
testcase_24 AC 286 ms
89,488 KB
testcase_25 AC 283 ms
89,184 KB
testcase_26 AC 410 ms
91,512 KB
testcase_27 AC 400 ms
91,452 KB
testcase_28 AC 142 ms
85,512 KB
testcase_29 AC 370 ms
89,268 KB
testcase_30 AC 148 ms
85,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = []
    h0 = -1
    c = "z"
    for h,w in Q:
        if w < W - 1 and h > h0:
            if S[h][w + 1] == c:
                Q2.append((h,w + 1))
            elif S[h][w + 1] < c:
                c = S[h][w + 1]
                Q2 = [(h,w + 1)]
            h0 = h
        if h < H - 1 and h + 1 > h0:
            if S[h + 1][w] == c:
                Q2.append((h + 1,w))
            elif S[h + 1][w] < c:
                c = S[h + 1][w]
                Q2 = [(h + 1,w)]
            h0 = h + 1
    #print(Q2)
    Q = Q2
    T.append(c)

print("".join(T))
0