結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー | Akari |
提出日時 | 2022-09-02 22:16:41 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 962 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 82,080 KB |
実行使用メモリ | 726,716 KB |
最終ジャッジ日時 | 2024-04-27 21:51:15 |
合計ジャッジ時間 | 6,166 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
59,688 KB |
testcase_01 | AC | 33 ms
53,636 KB |
testcase_02 | AC | 32 ms
53,324 KB |
testcase_03 | AC | 32 ms
53,632 KB |
testcase_04 | AC | 32 ms
53,396 KB |
testcase_05 | AC | 35 ms
53,340 KB |
testcase_06 | AC | 36 ms
53,744 KB |
testcase_07 | AC | 35 ms
52,744 KB |
testcase_08 | AC | 37 ms
54,312 KB |
testcase_09 | AC | 34 ms
53,140 KB |
testcase_10 | AC | 36 ms
53,808 KB |
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 | -- | - |
ソースコード
def main(): h, w = map(int, input().split()) A = [input() for _ in range(h)] B = [[0] * w for _ in range(h)] d = {A[0][0]: [(0, 0)]} for _ in range(h + w - 1): s = min(d) q = [(i, j) for i, j in d[s]] d.clear() while q: i, j = q.pop() B[i][j] = 1 if i < h - 1: a = A[i + 1][j] if a in d: d[a].append((i + 1, j)) else: d[a] = [(i + 1, j)] if j < w - 1: a = A[i][j + 1] if a in d: d[a].append((i, j + 1)) else: d[a] = [(i, j + 1)] ans = [] i, j = h - 1, w - 1 for _ in range(h + w - 1): ans.append(A[i][j]) if i > 0 and B[i - 1][j]: i -= 1 else: j -= 1 print(''.join(reversed(ans))) if __name__ == '__main__': main()