結果
問題 | No.2731 Two Colors |
ユーザー | Shirotsume |
提出日時 | 2024-04-19 22:59:12 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,727 bytes |
コンパイル時間 | 389 ms |
コンパイル使用メモリ | 82,116 KB |
実行使用メモリ | 133,036 KB |
最終ジャッジ日時 | 2024-04-19 23:00:02 |
合計ジャッジ時間 | 29,772 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | TLE | - |
testcase_03 | AC | 136 ms
78,464 KB |
testcase_04 | AC | 197 ms
80,084 KB |
testcase_05 | AC | 201 ms
79,460 KB |
testcase_06 | AC | 379 ms
87,160 KB |
testcase_07 | AC | 285 ms
85,440 KB |
testcase_08 | AC | 176 ms
79,428 KB |
testcase_09 | AC | 620 ms
106,892 KB |
testcase_10 | AC | 173 ms
78,464 KB |
testcase_11 | AC | 1,133 ms
130,308 KB |
testcase_12 | AC | 583 ms
104,388 KB |
testcase_13 | AC | 994 ms
121,048 KB |
testcase_14 | AC | 364 ms
91,292 KB |
testcase_15 | AC | 169 ms
79,036 KB |
testcase_16 | AC | 585 ms
97,044 KB |
testcase_17 | AC | 631 ms
100,512 KB |
testcase_18 | AC | 259 ms
81,728 KB |
testcase_19 | AC | 592 ms
100,240 KB |
testcase_20 | AC | 384 ms
92,968 KB |
testcase_21 | AC | 254 ms
82,180 KB |
testcase_22 | AC | 853 ms
117,004 KB |
testcase_23 | AC | 391 ms
89,132 KB |
testcase_24 | AC | 236 ms
81,848 KB |
testcase_25 | AC | 129 ms
78,428 KB |
testcase_26 | AC | 590 ms
102,912 KB |
testcase_27 | AC | 763 ms
112,752 KB |
testcase_28 | AC | 741 ms
107,620 KB |
testcase_29 | AC | 359 ms
86,972 KB |
testcase_30 | AC | 391 ms
90,740 KB |
testcase_31 | AC | 386 ms
89,340 KB |
testcase_32 | AC | 1,163 ms
133,036 KB |
testcase_33 | AC | 46 ms
55,680 KB |
testcase_34 | AC | 46 ms
55,552 KB |
testcase_35 | AC | 46 ms
55,936 KB |
ソースコード
import sys, time, random from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 61 - 1 mod = 998244353 import heapq class Heap(): def __init__(self, maxi = False): self.sum = 0 self.al = [] self.maxi = maxi self.len = 0 def __len__(self): return len(self.al) def add(self, x): if self.maxi: heapq.heappush(self.al, -x) else: heapq.heappush(self.al, x) def pop(self): if self.maxi: now = heapq.heappop(self.al) return -now else: now = heapq.heappop(self.al) return now def top(self): now = self.pop() self.add(now) return now h, w = mi() a = [li() for _ in range(h)] zero = Heap() one = Heap() color = [[-1] * w for _ in range(h)] zero.add((a[0][0], 0, 0)) one.add((a[h - 1][w - 1], h - 1, w - 1)) i = 0 while True: if i % 2 == 0: now, x, y = zero.pop() else: now, x, y = one.pop() if color[x][y] != -1: continue color[x][y] = i % 2 f = True for tox, toy in [(1, 0), (-1, 0), (0, 1), (0, -1)]: nx, ny = x + tox, y + toy if 0 <= nx < h and 0 <= ny < w and color[nx][ny] == -1: if i % 2 == 0: zero.add((a[nx][ny], nx, ny)) else: one.add((a[nx][ny], nx, ny)) elif 0 <= nx < h and 0 <= ny < w and color[nx][ny] == 1 - color[x][y] and color[nx][ny] != -1: f = False break i += 1 if not f: break print(i - 2)