結果

問題 No.2731 Two Colors
ユーザー hiro1729hiro1729
提出日時 2024-04-14 12:34:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 798 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 82,720 KB
実行使用メモリ 250,792 KB
最終ジャッジ日時 2024-04-14 14:27:20
合計ジャッジ時間 20,669 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,778 ms
250,660 KB
testcase_01 AC 1,781 ms
250,792 KB
testcase_02 AC 1,786 ms
250,404 KB
testcase_03 AC 104 ms
76,940 KB
testcase_04 WA -
testcase_05 AC 146 ms
80,772 KB
testcase_06 AC 260 ms
105,040 KB
testcase_07 AC 228 ms
115,988 KB
testcase_08 AC 117 ms
78,844 KB
testcase_09 AC 567 ms
234,268 KB
testcase_10 AC 111 ms
77,180 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 782 ms
183,180 KB
testcase_14 WA -
testcase_15 AC 123 ms
78,080 KB
testcase_16 AC 401 ms
127,212 KB
testcase_17 WA -
testcase_18 AC 171 ms
85,184 KB
testcase_19 WA -
testcase_20 AC 365 ms
179,280 KB
testcase_21 AC 190 ms
85,836 KB
testcase_22 AC 708 ms
226,140 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 514 ms
208,644 KB
testcase_27 AC 635 ms
222,588 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 284 ms
102,008 KB
testcase_32 AC 943 ms
239,572 KB
testcase_33 AC 39 ms
52,524 KB
testcase_34 AC 40 ms
54,024 KB
testcase_35 AC 39 ms
54,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
assert(len(set([A[i][j] for i in range(H) for j in range(W)])) == H * W)
q = [[], []]
C = [[-1] * W for _ in range(H)]
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[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 -1 != C[x][y] != C[i][j]:
				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[k % 2][x][y] == 0:
				heappush(q[k % 2], (A[x][y], x, y))
				B[k % 2][x][y] = 1
0