結果

問題 No.2064 Smallest Sequence on Grid
ユーザー H20
提出日時 2022-09-02 22:23:07
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 713 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 82,044 KB
実行使用メモリ 845,184 KB
最終ジャッジ日時 2024-11-16 04:17:07
合計ジャッジ時間 25,479 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 4 RE * 22 TLE * 2 MLE * 1
権限があれば一括ダウンロードができます

ソースコード

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,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