結果

問題 No.2064 Smallest Sequence on Grid
ユーザー qib
提出日時 2024-12-29 13:52:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,127 ms / 3,000 ms
コード長 597 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 82,604 KB
実行使用メモリ 110,304 KB
最終ジャッジ日時 2024-12-29 13:52:39
合計ジャッジ時間 19,464 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

h, w = map(int, input().split())
s = [input() for _ in range(h)]

dx = [1, 0]
dy = [0, 1]

cands = set()
cands.add((0, 0))
ans = [s[0][0]]
for i in range(h + w - 2):
  c = None
  nxt_cands = set()
  for cx, cy in cands:
    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]
        nxt_cands = set()
        nxt_cands.add((nx, ny))
      elif c == s[nx][ny]:
        nxt_cands.add((nx, ny))

  cands = nxt_cands
  ans.append(c)

print(*ans, sep='')
0