結果

問題 No.2731 Two Colors
ユーザー budoubudou
提出日時 2024-04-20 08:17:28
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,070 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 82,284 KB
実行使用メモリ 133,468 KB
最終ジャッジ日時 2024-04-20 08:18:05
合計ジャッジ時間 31,567 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 143 ms
79,256 KB
testcase_04 AC 187 ms
80,580 KB
testcase_05 AC 187 ms
80,380 KB
testcase_06 AC 321 ms
87,844 KB
testcase_07 AC 265 ms
86,568 KB
testcase_08 AC 172 ms
80,164 KB
testcase_09 AC 584 ms
106,376 KB
testcase_10 AC 150 ms
79,928 KB
testcase_11 AC 1,160 ms
130,924 KB
testcase_12 AC 544 ms
105,772 KB
testcase_13 AC 947 ms
121,928 KB
testcase_14 AC 344 ms
91,628 KB
testcase_15 AC 179 ms
80,128 KB
testcase_16 AC 556 ms
98,132 KB
testcase_17 AC 539 ms
102,032 KB
testcase_18 AC 247 ms
82,668 KB
testcase_19 AC 577 ms
100,216 KB
testcase_20 AC 366 ms
94,192 KB
testcase_21 AC 280 ms
82,628 KB
testcase_22 AC 844 ms
118,584 KB
testcase_23 AC 364 ms
89,504 KB
testcase_24 AC 225 ms
83,464 KB
testcase_25 AC 129 ms
79,312 KB
testcase_26 AC 565 ms
105,332 KB
testcase_27 AC 739 ms
112,856 KB
testcase_28 AC 653 ms
107,020 KB
testcase_29 AC 346 ms
88,036 KB
testcase_30 AC 383 ms
91,688 KB
testcase_31 AC 386 ms
90,644 KB
testcase_32 AC 1,144 ms
133,468 KB
testcase_33 AC 63 ms
68,616 KB
testcase_34 AC 61 ms
68,144 KB
testcase_35 AC 75 ms
69,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0