結果

問題 No.2064 Smallest Sequence on Grid
ユーザー roarisroaris
提出日時 2022-09-24 17:57:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,458 ms / 3,000 ms
コード長 632 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 102,532 KB
最終ジャッジ日時 2023-08-24 00:31:53
合計ジャッジ時間 15,782 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,368 KB
testcase_01 AC 67 ms
71,396 KB
testcase_02 AC 67 ms
71,584 KB
testcase_03 AC 68 ms
71,244 KB
testcase_04 AC 66 ms
71,408 KB
testcase_05 AC 67 ms
71,340 KB
testcase_06 AC 66 ms
71,172 KB
testcase_07 AC 67 ms
71,124 KB
testcase_08 AC 67 ms
71,440 KB
testcase_09 AC 66 ms
71,248 KB
testcase_10 AC 67 ms
71,388 KB
testcase_11 AC 67 ms
71,648 KB
testcase_12 AC 66 ms
71,372 KB
testcase_13 AC 71 ms
76,340 KB
testcase_14 AC 76 ms
76,124 KB
testcase_15 AC 74 ms
75,996 KB
testcase_16 AC 76 ms
76,200 KB
testcase_17 AC 122 ms
86,460 KB
testcase_18 AC 121 ms
86,248 KB
testcase_19 AC 121 ms
86,488 KB
testcase_20 AC 1,073 ms
96,476 KB
testcase_21 AC 1,146 ms
96,940 KB
testcase_22 AC 793 ms
92,936 KB
testcase_23 AC 803 ms
94,136 KB
testcase_24 AC 810 ms
94,260 KB
testcase_25 AC 803 ms
94,528 KB
testcase_26 AC 1,439 ms
101,884 KB
testcase_27 AC 1,458 ms
101,884 KB
testcase_28 AC 120 ms
86,672 KB
testcase_29 AC 1,285 ms
102,532 KB
testcase_30 AC 131 ms
85,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

H, W = map(int, input().split())
S = [input()[:-1] for _ in range(H)]
now = {(0, 0)}
ans = [S[0][0]]

for _ in range(H+W-2):
    m = 'z'
    nex = set()
    
    for x, y in now:
        if x+1<H:
            if m==S[x+1][y]:
                nex.add((x+1, y))
            elif m>S[x+1][y]:
                m = S[x+1][y]
                nex = {(x+1, y)}
        
        if y+1<W:
            if m==S[x][y+1]:
                nex.add((x, y+1))
            elif m>S[x][y+1]:
                m = S[x][y+1]
                nex = {(x, y+1)}
    
    ans.append(m)
    now = nex

print(''.join(ans))
0