結果
| 問題 |
No.2731 Two Colors
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-20 08:17:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,070 bytes |
| コンパイル時間 | 439 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 133,608 KB |
| 最終ジャッジ日時 | 2024-10-12 03:40:09 |
| 合計ジャッジ時間 | 32,221 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 TLE * 3 |
ソースコード
import typing
import sys
from collections import defaultdict
import heapq
input = lambda: sys.stdin.readline().strip()
inf = 10**18
mod = 998244353
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
# sys.setrecursionlimit(10**6)
def solve():
H, W = map(int, input().split())
grid = []
for _ in range(H):
grid.append(list(map(int, input().split())))
color = [[-1]*W for _ in range(H)]
q = [[(grid[-1][-1], H-1, W-1)], [(grid[0][0], 0, 0)]]
cnt = -2
while True:
while True:
_, h, w = heapq.heappop(q[(cnt-1)%2])
if color[h][w] == -1:
break
cnt += 1
color[h][w] = cnt%2
# 隣あっているマスに異なるいろがあったら終わり
for dh, dw in zip([1, 0, -1, 0], [0, 1, 0, -1]):
if 0 <= dh + h <= H-1 and 0 <= dw + w <= W-1:
if color[dh + h][dw + w]==-1:
heapq.heappush(q[cnt%2], (grid[dh+h][dw+w], dh+h, dw+w))
if color[dh + h][dw + w]==(cnt-1)%2:
print(cnt)
return
def main():
t = 1
for _ in range(t):
solve()
main()