結果

問題 No.2064 Smallest Sequence on Grid
コンテスト
ユーザー H20
提出日時 2022-09-02 22:23:07
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
RE  
実行時間 -
コード長 713 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 842 ms
コンパイル使用メモリ 84,864 KB
実行使用メモリ 453,760 KB
最終ジャッジ日時 2026-05-11 08:11:03
合計ジャッジ時間 18,380 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 RE * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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

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