結果
| 問題 | No.2064 Smallest Sequence on Grid |
| コンテスト | |
| ユーザー |
ikoma
|
| 提出日時 | 2022-09-02 21:45:01 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 765 ms / 3,000 ms |
| コード長 | 771 bytes |
| 記録 | |
| コンパイル時間 | 328 ms |
| コンパイル使用メモリ | 85,248 KB |
| 実行使用メモリ | 252,416 KB |
| 最終ジャッジ日時 | 2026-05-11 06:56:31 |
| 合計ジャッジ時間 | 9,737 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
S=[list(map(lambda x:ord(x),input())) for _ in range(H)]
INF=1<<60
check = [[0]*W for _ in range(H)]
ans = [S[0][0]]
que = [(0,0)]
check[0][0]=1
while que:
que2 = []
smin = INF
for h,w in que:
if h+1<H and check[h+1][w]==0:
check[h+1][w]=1
s = S[h+1][w]
if s < smin:
smin = s
que2.append((s,h+1,w))
if w+1<W and check[h][w+1]==0:
check[h][w+1]=1
s = S[h][w+1]
if s < smin:
smin = s
que2.append((s,h,w+1))
ans.append(smin)
que = []
for s,h,w in que2:
if s==smin:
que.append((h,w))
print("".join(map(chr, ans[:-1])))
ikoma