結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー | Shirotsume |
提出日時 | 2022-09-02 22:47:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,392 bytes |
コンパイル時間 | 174 ms |
コンパイル使用メモリ | 82,180 KB |
実行使用メモリ | 848,732 KB |
最終ジャッジ日時 | 2024-04-27 22:24:27 |
合計ジャッジ時間 | 5,085 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
54,808 KB |
testcase_01 | AC | 37 ms
54,636 KB |
testcase_02 | AC | 35 ms
54,596 KB |
testcase_03 | AC | 34 ms
54,148 KB |
testcase_04 | AC | 35 ms
53,864 KB |
testcase_05 | AC | 36 ms
55,340 KB |
testcase_06 | WA | - |
testcase_07 | AC | 35 ms
54,792 KB |
testcase_08 | AC | 35 ms
55,492 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | MLE | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
ソースコード
from collections import deque import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 h, w = mi() a = [input() for _ in range(h)] dp = [[inf] * w for _ in range(h)] dp[0][0] = 0 q = deque() q.append((0, 0)) while q: nowi, nowj = q.popleft() if nowi + 1 < h and nowj + 1 < w: if a[nowi+1][nowj] == a[nowi][nowj+1]: dp[nowi][nowj+1]=dp[nowi+1][nowj] = dp[nowi][nowj]+1 q.append((nowi,nowj+1)) q.append((nowi+1, nowj)) elif a[nowi+1][nowj]<a[nowi][nowj+1]: dp[nowi+1][nowj]=dp[nowi][nowj]+1 q.append((nowi+1,nowj)) else: dp[nowi][nowj+1]=dp[nowi][nowj]+1 q.append((nowi,nowj+1)) elif nowi+1<h: dp[nowi+1][nowj]=dp[nowi][nowj]+1 q.append((nowi+1,nowj)) elif nowj+1<w: dp[nowi][nowj+1]=dp[nowi][nowj]+1 q.append((nowi,nowj+1)) q = deque() q.append((0, 0)) ans = [a[0][0]] while q: nowi,nowj=q.popleft() if nowi == h - 1 and nowj == w - 1: break if nowi + 1 < h and dp[nowi+1][nowj] == dp[nowi][nowj]+1: ans.append(a[nowi+1][nowj]) q.append((nowi+1,nowj)) else: ans.append(a[nowi][nowj+1]) q.append((nowi,nowj+1)) print(''.join(ans))