結果

問題 No.2064 Smallest Sequence on Grid
ユーザー qibqib
提出日時 2023-04-28 15:51:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,814 ms / 3,000 ms
コード長 588 bytes
コンパイル時間 1,747 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 501,812 KB
最終ジャッジ日時 2023-08-11 03:14:29
合計ジャッジ時間 23,040 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,668 KB
testcase_01 AC 76 ms
71,528 KB
testcase_02 AC 77 ms
71,648 KB
testcase_03 AC 77 ms
71,520 KB
testcase_04 AC 84 ms
71,612 KB
testcase_05 AC 79 ms
71,576 KB
testcase_06 AC 78 ms
71,472 KB
testcase_07 AC 80 ms
71,744 KB
testcase_08 AC 85 ms
71,460 KB
testcase_09 AC 83 ms
71,616 KB
testcase_10 AC 90 ms
71,640 KB
testcase_11 AC 105 ms
77,372 KB
testcase_12 AC 85 ms
77,196 KB
testcase_13 AC 88 ms
77,408 KB
testcase_14 AC 88 ms
77,276 KB
testcase_15 AC 90 ms
77,288 KB
testcase_16 AC 92 ms
77,396 KB
testcase_17 AC 148 ms
87,404 KB
testcase_18 AC 143 ms
87,364 KB
testcase_19 AC 145 ms
87,356 KB
testcase_20 AC 1,924 ms
383,396 KB
testcase_21 AC 2,199 ms
407,684 KB
testcase_22 AC 1,199 ms
309,692 KB
testcase_23 AC 1,266 ms
294,844 KB
testcase_24 AC 1,293 ms
295,068 KB
testcase_25 AC 1,292 ms
295,148 KB
testcase_26 AC 2,708 ms
500,368 KB
testcase_27 AC 2,814 ms
501,812 KB
testcase_28 AC 147 ms
87,168 KB
testcase_29 AC 1,980 ms
424,860 KB
testcase_30 AC 153 ms
86,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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='')
0