結果

問題 No.2731 Two Colors
ユーザー hiro1729hiro1729
提出日時 2024-04-14 12:49:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,678 ms / 3,000 ms
コード長 785 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 129,212 KB
最終ジャッジ日時 2024-04-14 14:27:43
合計ジャッジ時間 18,900 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,678 ms
129,212 KB
testcase_01 AC 1,675 ms
128,784 KB
testcase_02 AC 1,670 ms
128,776 KB
testcase_03 AC 100 ms
76,860 KB
testcase_04 AC 130 ms
79,360 KB
testcase_05 AC 130 ms
78,128 KB
testcase_06 AC 237 ms
84,184 KB
testcase_07 AC 195 ms
84,652 KB
testcase_08 AC 113 ms
77,396 KB
testcase_09 AC 458 ms
109,232 KB
testcase_10 AC 103 ms
77,152 KB
testcase_11 AC 846 ms
114,840 KB
testcase_12 AC 438 ms
109,204 KB
testcase_13 AC 719 ms
108,272 KB
testcase_14 AC 281 ms
90,568 KB
testcase_15 AC 118 ms
77,660 KB
testcase_16 AC 369 ms
90,576 KB
testcase_17 AC 403 ms
96,188 KB
testcase_18 AC 155 ms
79,432 KB
testcase_19 AC 399 ms
92,188 KB
testcase_20 AC 284 ms
96,952 KB
testcase_21 AC 177 ms
80,628 KB
testcase_22 AC 607 ms
113,036 KB
testcase_23 AC 241 ms
84,524 KB
testcase_24 AC 173 ms
80,588 KB
testcase_25 AC 105 ms
76,704 KB
testcase_26 AC 429 ms
103,580 KB
testcase_27 AC 545 ms
111,788 KB
testcase_28 AC 498 ms
100,072 KB
testcase_29 AC 223 ms
83,428 KB
testcase_30 AC 277 ms
88,920 KB
testcase_31 AC 267 ms
84,968 KB
testcase_32 AC 838 ms
123,568 KB
testcase_33 AC 39 ms
53,284 KB
testcase_34 AC 37 ms
53,280 KB
testcase_35 AC 38 ms
53,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
q = [[], []]
C = [[[-1] * W for _ in range(H)] for _ in range(2)]
B = [[[0] * W for _ in range(H)] for _ in range(2)]
heappush(q[1], (A[0][0], 0, 0))
heappush(q[0], (A[H - 1][W - 1], H - 1, W - 1))
B[1][0][0] = 1
B[0][H - 1][W - 1] = 1
for k in range(1, H * W + 1):
	_, i, j = heappop(q[k % 2])
	C[k % 2][i][j] = 0
	for dx, dy in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
		x = i + dx
		y = j + dy
		if 0 <= x < H and 0 <= y < W:
			if C[1 - k % 2][x][y] == 0:
				exit(print(k - 2))
	for dx, dy in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
		x = i + dx
		y = j + dy
		if 0 <= x < H and 0 <= y < W:
			if B[k % 2][x][y] == 0:
				heappush(q[k % 2], (A[x][y], x, y))
				B[k % 2][x][y] = 1
0