結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー |
|
提出日時 | 2022-09-02 22:47:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,392 bytes |
コンパイル時間 | 681 ms |
コンパイル使用メモリ | 82,240 KB |
実行使用メモリ | 1,224,760 KB |
最終ジャッジ日時 | 2024-11-16 05:12:47 |
合計ジャッジ時間 | 65,987 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
60,196 KB |
testcase_01 | AC | 42 ms
62,852 KB |
testcase_02 | AC | 41 ms
59,008 KB |
testcase_03 | AC | 41 ms
481,948 KB |
testcase_04 | AC | 42 ms
59,392 KB |
testcase_05 | AC | 43 ms
53,760 KB |
testcase_06 | WA | - |
testcase_07 | AC | 43 ms
53,760 KB |
testcase_08 | AC | 43 ms
53,888 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | MLE | - |
testcase_22 | MLE | - |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | MLE | - |
testcase_26 | TLE | - |
testcase_27 | MLE | - |
testcase_28 | WA | - |
testcase_29 | TLE | - |
testcase_30 | MLE | - |
ソースコード
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))