結果

問題 No.2731 Two Colors
ユーザー hiro1729hiro1729
提出日時 2024-04-14 12:37:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 767 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 82,204 KB
実行使用メモリ 129,052 KB
最終ジャッジ日時 2024-04-14 14:27:32
合計ジャッジ時間 18,968 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,659 ms
129,052 KB
testcase_01 AC 1,647 ms
128,760 KB
testcase_02 AC 1,657 ms
128,820 KB
testcase_03 AC 100 ms
76,864 KB
testcase_04 WA -
testcase_05 AC 136 ms
78,512 KB
testcase_06 AC 232 ms
83,932 KB
testcase_07 AC 193 ms
84,592 KB
testcase_08 AC 113 ms
77,616 KB
testcase_09 AC 448 ms
109,304 KB
testcase_10 AC 107 ms
76,644 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 702 ms
108,648 KB
testcase_14 WA -
testcase_15 AC 118 ms
77,640 KB
testcase_16 AC 362 ms
90,672 KB
testcase_17 WA -
testcase_18 AC 160 ms
79,404 KB
testcase_19 WA -
testcase_20 AC 282 ms
97,268 KB
testcase_21 AC 178 ms
80,736 KB
testcase_22 AC 607 ms
112,256 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 432 ms
104,208 KB
testcase_27 AC 530 ms
111,584 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 260 ms
84,840 KB
testcase_32 AC 823 ms
123,616 KB
testcase_33 AC 38 ms
53,144 KB
testcase_34 AC 38 ms
53,340 KB
testcase_35 AC 38 ms
53,512 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))
for k in range(1, H * W + 1):
	_, i, j = heappop(q[k % 2])
	C[k % 2][i][j] = 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 C[1 - k % 2][x][y] == 1 - k % 2:
				exit(print(k - 4))
	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[1 - k % 2][x][y] == 0:
				heappush(q[k % 2], (A[x][y], x, y))
				B[1 - k % 2][x][y] = 1
0