結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 H20H20
提出日時 2022-09-02 22:30:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,376 ms / 3,000 ms
コード長 768 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 439,752 KB
最終ジャッジ日時 2024-04-27 22:07:25
合計ジャッジ時間 23,426 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,144 KB
testcase_01 AC 37 ms
52,892 KB
testcase_02 AC 38 ms
52,648 KB
testcase_03 AC 37 ms
53,224 KB
testcase_04 AC 38 ms
53,504 KB
testcase_05 AC 38 ms
53,816 KB
testcase_06 AC 37 ms
52,192 KB
testcase_07 AC 37 ms
52,560 KB
testcase_08 AC 39 ms
53,684 KB
testcase_09 AC 38 ms
53,856 KB
testcase_10 AC 40 ms
54,408 KB
testcase_11 AC 39 ms
53,564 KB
testcase_12 AC 39 ms
53,876 KB
testcase_13 AC 45 ms
61,920 KB
testcase_14 AC 47 ms
60,744 KB
testcase_15 AC 45 ms
59,892 KB
testcase_16 AC 46 ms
60,040 KB
testcase_17 AC 769 ms
425,144 KB
testcase_18 AC 743 ms
425,276 KB
testcase_19 AC 736 ms
425,260 KB
testcase_20 AC 1,848 ms
435,916 KB
testcase_21 AC 1,921 ms
436,604 KB
testcase_22 AC 1,505 ms
434,304 KB
testcase_23 AC 1,538 ms
435,772 KB
testcase_24 AC 1,535 ms
435,544 KB
testcase_25 AC 1,536 ms
435,756 KB
testcase_26 AC 2,376 ms
439,400 KB
testcase_27 AC 2,369 ms
439,752 KB
testcase_28 AC 734 ms
425,340 KB
testcase_29 AC 2,126 ms
380,472 KB
testcase_30 AC 709 ms
401,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()+'~'))
S.append(list('~'*(W+2)))

pos = set()
pos.add(0)
ANS = [S[0][0]]

while len(ANS)<H+W-1:
    alphabet = 'z'
    nextPos = set()
    for xy in list(pos):
        x,y = xy%W,xy//W
        if S[y][x+1]==alphabet:
            nextPos.add(xy+1)
        elif S[y][x+1]<alphabet:
            alphabet = S[y][x+1]
            nextPos = set()
            nextPos.add(xy+1)
        if not xy+W in nextPos:
            if S[y+1][x]==alphabet:
                nextPos.add(xy+W)
            elif S[y+1][x]<alphabet:
                alphabet = S[y+1][x]
                nextPos = set()
                nextPos.add(xy+W)
    ANS.append(alphabet)
    pos = nextPos
print(''.join(map(str, ANS)))
0