結果
問題 | No.2731 Two Colors |
ユーザー | 👑 KA37RI |
提出日時 | 2024-04-19 22:26:37 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,482 bytes |
コンパイル時間 | 506 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 132,276 KB |
最終ジャッジ日時 | 2024-10-11 15:56:48 |
合計ジャッジ時間 | 29,792 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | TLE | - |
testcase_03 | AC | 139 ms
77,440 KB |
testcase_04 | AC | 203 ms
79,380 KB |
testcase_05 | AC | 216 ms
79,288 KB |
testcase_06 | AC | 345 ms
86,228 KB |
testcase_07 | AC | 314 ms
85,096 KB |
testcase_08 | AC | 175 ms
77,440 KB |
testcase_09 | AC | 628 ms
105,612 KB |
testcase_10 | AC | 179 ms
77,492 KB |
testcase_11 | AC | 1,163 ms
129,148 KB |
testcase_12 | AC | 576 ms
103,920 KB |
testcase_13 | AC | 1,009 ms
121,268 KB |
testcase_14 | AC | 405 ms
90,612 KB |
testcase_15 | AC | 203 ms
78,140 KB |
testcase_16 | AC | 525 ms
95,796 KB |
testcase_17 | AC | 549 ms
99,528 KB |
testcase_18 | AC | 243 ms
81,220 KB |
testcase_19 | AC | 559 ms
97,328 KB |
testcase_20 | AC | 404 ms
92,208 KB |
testcase_21 | AC | 263 ms
80,852 KB |
testcase_22 | AC | 856 ms
115,816 KB |
testcase_23 | AC | 356 ms
86,376 KB |
testcase_24 | AC | 264 ms
80,728 KB |
testcase_25 | AC | 129 ms
76,648 KB |
testcase_26 | AC | 610 ms
102,940 KB |
testcase_27 | AC | 707 ms
110,592 KB |
testcase_28 | AC | 711 ms
105,984 KB |
testcase_29 | AC | 350 ms
86,252 KB |
testcase_30 | AC | 414 ms
89,480 KB |
testcase_31 | AC | 415 ms
88,700 KB |
testcase_32 | AC | 1,143 ms
132,276 KB |
testcase_33 | AC | 41 ms
52,864 KB |
testcase_34 | AC | 41 ms
52,864 KB |
testcase_35 | AC | 41 ms
52,224 KB |
ソースコード
import heapq def solve(h, w, a): col = [[-1] * w for _ in range(h)] ans = 0 queue0 = [(a[0][0], 0, 0)] queue1 = [(a[h-1][w-1], h-1, w-1)] while True: ans += 1 filled = False while True: if queue0: _, i, j = heapq.heappop(queue0) if col[i][j] != -1: continue filled = True col[i][j] = 0 for di, dj in [(1, 0), (-1, 0), (0, 1), (0, -1)]: ni, nj = i + di, j + dj if ni < 0 or ni >= h or nj < 0 or nj >= w: continue if col[ni][nj] == 0: continue elif col[ni][nj] == 1: return ans - 2 else: heapq.heappush(queue0, (a[ni][nj], ni, nj)) if filled: break ans += 1 while True: if queue1: _, i, j = heapq.heappop(queue1) if col[i][j] != -1: continue filled = True col[i][j] = 1 for di, dj in [(1, 0), (-1, 0), (0, 1), (0, -1)]: ni, nj = i + di, j + dj if ni < 0 or ni >= h or nj < 0 or nj >= w: continue if col[ni][nj] == 1: continue elif col[ni][nj] == 0: return ans - 2 else: heapq.heappush(queue1, (a[ni][nj], ni, nj)) if filled: break def main(): h, w = [int(x) for x in input().split()] a = [[int(x) for x in input().split()] for _ in range(h)] print(solve(h, w, a)) if __name__ == "__main__": main()