結果

問題 No.2731 Two Colors
ユーザー flygonflygon
提出日時 2024-04-19 21:51:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,703 ms / 3,000 ms
コード長 1,340 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 113,408 KB
最終ジャッジ日時 2024-04-19 21:52:13
合計ジャッジ時間 18,139 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,642 ms
108,544 KB
testcase_01 AC 1,703 ms
108,544 KB
testcase_02 AC 1,649 ms
108,544 KB
testcase_03 AC 148 ms
78,592 KB
testcase_04 AC 193 ms
79,872 KB
testcase_05 AC 181 ms
80,000 KB
testcase_06 AC 244 ms
84,096 KB
testcase_07 AC 234 ms
83,072 KB
testcase_08 AC 172 ms
79,360 KB
testcase_09 AC 374 ms
97,664 KB
testcase_10 AC 159 ms
78,592 KB
testcase_11 AC 602 ms
108,928 KB
testcase_12 AC 353 ms
96,896 KB
testcase_13 AC 531 ms
105,344 KB
testcase_14 AC 288 ms
87,424 KB
testcase_15 AC 172 ms
78,720 KB
testcase_16 AC 331 ms
89,856 KB
testcase_17 AC 355 ms
92,800 KB
testcase_18 AC 213 ms
79,616 KB
testcase_19 AC 351 ms
91,008 KB
testcase_20 AC 281 ms
88,960 KB
testcase_21 AC 204 ms
80,000 KB
testcase_22 AC 473 ms
103,168 KB
testcase_23 AC 254 ms
83,968 KB
testcase_24 AC 205 ms
80,128 KB
testcase_25 AC 136 ms
78,464 KB
testcase_26 AC 369 ms
95,360 KB
testcase_27 AC 454 ms
101,632 KB
testcase_28 AC 412 ms
95,616 KB
testcase_29 AC 245 ms
83,072 KB
testcase_30 AC 272 ms
86,272 KB
testcase_31 AC 279 ms
84,864 KB
testcase_32 AC 581 ms
113,408 KB
testcase_33 AC 42 ms
55,040 KB
testcase_34 AC 43 ms
55,040 KB
testcase_35 AC 42 ms
54,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

h,w = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]

col = [[-1]*(w) for i in range(h)]
r = [(a[0][0],0*w+0)]
b = [(a[-1][-1],(h-1)*w+(w-1))]

dx = [1,-1,0,0]
dy = [0,0,1,-1]
for i in range(h*w+10):
    if i % 2 == 0:
        while r:
            num, crr = heappop(r)
            x, y = crr//w, crr%w
            if col[x][y] == -1:
                col[x][y] = 1
                break
        for j in range(4):
            nx = x+dx[j]
            ny = y+dy[j]
            if not (0<=nx<h and 0<=ny<w):continue
            if col[nx][ny] == 0:
                print(i-1)
                exit()
            heappush(r, (a[nx][ny],nx*w+ny))
    else:
        while b:
            num, crr = heappop(b)
            x, y = crr//w, crr%w
            if col[x][y] == -1:
                col[x][y] = 0
                break
        for j in range(4):
            nx = x+dx[j]
            ny = y+dy[j]
            if not (0<=nx<h and 0<=ny<w):continue
            if col[nx][ny] == 1:
                print(i-1)
                exit()
            heappush(b, (a[nx][ny], nx*w+ny))

    

0