結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー | shobonvip |
提出日時 | 2022-09-02 21:58:58 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 822 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 81,832 KB |
実行使用メモリ | 65,264 KB |
最終ジャッジ日時 | 2024-04-27 21:31:14 |
合計ジャッジ時間 | 6,089 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
60,040 KB |
testcase_01 | AC | 33 ms
53,076 KB |
testcase_02 | AC | 32 ms
52,220 KB |
testcase_03 | AC | 31 ms
52,524 KB |
testcase_04 | AC | 36 ms
53,416 KB |
testcase_05 | AC | 37 ms
52,828 KB |
testcase_06 | AC | 34 ms
52,340 KB |
testcase_07 | AC | 37 ms
52,460 KB |
testcase_08 | AC | 35 ms
54,176 KB |
testcase_09 | AC | 33 ms
53,496 KB |
testcase_10 | TLE | - |
testcase_11 | -- | - |
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 | -- | - |
ソースコード
h,w = map(int,input().split()) s = [input() for i in range(h)] # BFSっぽいのをする. (ただし少し特殊) mada = [(0,0)] t = [0] * h*w t[0] = 1 while mada: k = 26 for x, y in mada: if x < h-1: k = min(k, ord(s[x+1][y]) - ord("a")) if y < w-1: k = min(k, ord(s[x][y+1]) - ord("a")) fr = [] for i in mada: if x < h-1: if ord(s[x+1][y]) - ord("a") == k: if t[(x+1)*w + y] == 0: fr.append((x+1, y)) t[(x+1)*w + y] = 1 if y < w-1: if ord(s[x][y+1]) - ord("a") == k: if t[x*w + y+1] == 0: fr.append((x, y+1)) t[x*w + y+1] = 1 mada = fr ans = [] x = h-1; y = w-1 while x > 0 or y > 0: if x > 0 and t[(x-1)*w + y] == 1: ans.append(s[x][y]) x -= 1 elif y > 0 and t[x*w + y-1] == 1: ans.append(s[x][y]) y -= 1 ans.append(s[0][0]) print("".join(ans[::-1]))