結果

問題 No.2731 Two Colors
ユーザー hiro1729hiro1729
提出日時 2024-04-15 07:05:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,698 ms / 3,000 ms
コード長 676 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 127,768 KB
最終ジャッジ日時 2024-04-15 07:05:59
合計ジャッジ時間 21,147 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,698 ms
127,768 KB
testcase_01 AC 1,654 ms
127,696 KB
testcase_02 AC 1,657 ms
127,312 KB
testcase_03 AC 102 ms
76,680 KB
testcase_04 AC 132 ms
79,360 KB
testcase_05 AC 134 ms
78,080 KB
testcase_06 AC 231 ms
83,968 KB
testcase_07 AC 192 ms
84,788 KB
testcase_08 AC 116 ms
77,440 KB
testcase_09 AC 454 ms
108,660 KB
testcase_10 AC 101 ms
76,556 KB
testcase_11 AC 850 ms
114,328 KB
testcase_12 AC 438 ms
108,424 KB
testcase_13 AC 712 ms
108,080 KB
testcase_14 AC 277 ms
90,348 KB
testcase_15 AC 116 ms
77,724 KB
testcase_16 AC 360 ms
90,752 KB
testcase_17 AC 405 ms
95,988 KB
testcase_18 AC 155 ms
79,624 KB
testcase_19 AC 394 ms
91,720 KB
testcase_20 AC 283 ms
95,920 KB
testcase_21 AC 180 ms
79,492 KB
testcase_22 AC 608 ms
112,096 KB
testcase_23 AC 268 ms
84,668 KB
testcase_24 AC 165 ms
79,980 KB
testcase_25 AC 103 ms
76,492 KB
testcase_26 AC 428 ms
103,676 KB
testcase_27 AC 544 ms
111,788 KB
testcase_28 AC 495 ms
99,504 KB
testcase_29 AC 222 ms
82,516 KB
testcase_30 AC 276 ms
88,504 KB
testcase_31 AC 260 ms
84,272 KB
testcase_32 AC 830 ms
122,952 KB
testcase_33 AC 42 ms
54,492 KB
testcase_34 AC 42 ms
53,064 KB
testcase_35 AC 40 ms
53,020 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))
			if B[k % 2][x][y] == 0:
				heappush(q[k % 2], (A[x][y], x, y))
				B[k % 2][x][y] = 1
0