結果

問題 No.2064 Smallest Sequence on Grid
コンテスト
ユーザー vwxyz
提出日時 2023-01-14 23:56:56
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,615 ms / 3,000 ms
+ 516µs
コード長 436 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 66 ms
コンパイル使用メモリ 81,124 KB
実行使用メモリ 137,992 KB
最終ジャッジ日時 2026-10-08 07:27:52
合計ジャッジ時間 15,820 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
readline=sys.stdin.readline

H,W=map(int,readline().split())
S=[readline().rstrip() for h in range(H)]
ans_lst=[S[0][0]]
queue=[(0,0)]
for _ in range(H+W-2):
    s=min([S[h+1][w] for h,w in queue if h+1<H]+[S[h][w+1] for h,w in queue if w+1<W])
    ans_lst.append(s)
    prev=queue
    queue=list({(h+1,w) for h,w in prev if h+1<H and S[h+1][w]==s}|{(h,w+1) for h,w in prev if w+1<W and S[h][w+1]==s})
print("".join(ans_lst))
0