結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 H20H20
提出日時 2022-09-02 22:27:02
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 764 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 439,464 KB
最終ジャッジ日時 2024-04-27 22:02:58
合計ジャッジ時間 24,646 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,332 KB
testcase_01 AC 37 ms
52,760 KB
testcase_02 AC 38 ms
52,188 KB
testcase_03 AC 38 ms
52,208 KB
testcase_04 RE -
testcase_05 AC 40 ms
54,152 KB
testcase_06 AC 39 ms
52,952 KB
testcase_07 AC 38 ms
52,896 KB
testcase_08 RE -
testcase_09 AC 39 ms
52,080 KB
testcase_10 AC 40 ms
54,800 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 AC 46 ms
60,364 KB
testcase_15 AC 46 ms
60,348 KB
testcase_16 AC 46 ms
62,012 KB
testcase_17 AC 750 ms
425,868 KB
testcase_18 AC 742 ms
425,032 KB
testcase_19 AC 733 ms
425,964 KB
testcase_20 AC 1,922 ms
435,720 KB
testcase_21 AC 2,076 ms
437,276 KB
testcase_22 AC 1,546 ms
434,576 KB
testcase_23 AC 1,640 ms
436,112 KB
testcase_24 AC 1,687 ms
435,896 KB
testcase_25 AC 1,631 ms
435,768 KB
testcase_26 AC 2,627 ms
439,436 KB
testcase_27 AC 2,623 ms
439,464 KB
testcase_28 AC 747 ms
425,648 KB
testcase_29 WA -
testcase_30 AC 715 ms
401,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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[x+1][y]==alphabet:
            nextPos.add(xy+1)
        elif S[x+1][y]<alphabet:
            alphabet = S[x+1][y]
            nextPos = set()
            nextPos.add(xy+1)
        if not xy+W in nextPos:
            if S[x][y+1]==alphabet:
                nextPos.add(xy+W)
            elif S[x][y+1]<alphabet:
                alphabet = S[x][y+1]
                nextPos = set()
                nextPos.add(xy+W)
    ANS.append(alphabet)
    pos = nextPos
print(''.join(map(str, ANS)))
0