結果
問題 |
No.2064 Smallest Sequence on Grid
|
ユーザー |
|
提出日時 | 2023-04-28 15:51:27 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 588 bytes |
コンパイル時間 | 227 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 499,584 KB |
最終ジャッジ日時 | 2024-11-17 15:34:24 |
合計ジャッジ時間 | 24,077 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 TLE * 2 |
ソースコード
from collections import deque h, w = map(int, input().split()) s = [input() for _ in range(h)] dx = [1, 0] dy = [0, 1] cands = [] cands.append(set()) cands[0].add((0, 0)) ans = [s[0][0]] for i in range(h + w - 2): c = None q = set() for cx, cy in cands[-1]: for j in range(2): nx = cx + dx[j] ny = cy + dy[j] if nx >= h or ny >= w: continue if c is None or c > s[nx][ny]: c = s[nx][ny] q = set() q.add((nx, ny)) elif c == s[nx][ny]: q.add((nx, ny)) cands.append(q) ans.append(c) print(*ans, sep='')