結果
問題 | No.2657 Falling Block Game |
ユーザー | 👑 rin204 |
提出日時 | 2024-03-03 16:40:48 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,743 bytes |
コンパイル時間 | 313 ms |
コンパイル使用メモリ | 82,300 KB |
実行使用メモリ | 196,896 KB |
最終ジャッジ日時 | 2024-09-29 16:54:41 |
合計ジャッジ時間 | 16,645 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
54,848 KB |
testcase_01 | AC | 40 ms
54,636 KB |
testcase_02 | AC | 38 ms
54,096 KB |
testcase_03 | AC | 39 ms
54,280 KB |
testcase_04 | AC | 211 ms
81,328 KB |
testcase_05 | AC | 491 ms
167,320 KB |
testcase_06 | AC | 350 ms
141,024 KB |
testcase_07 | AC | 431 ms
196,896 KB |
testcase_08 | AC | 268 ms
83,220 KB |
testcase_09 | AC | 341 ms
81,676 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 470 ms
82,744 KB |
testcase_31 | AC | 468 ms
82,404 KB |
testcase_32 | AC | 466 ms
83,040 KB |
testcase_33 | AC | 440 ms
82,764 KB |
testcase_34 | AC | 438 ms
82,920 KB |
testcase_35 | AC | 441 ms
82,948 KB |
testcase_36 | AC | 456 ms
83,076 KB |
testcase_37 | AC | 451 ms
83,176 KB |
testcase_38 | AC | 433 ms
83,088 KB |
testcase_39 | AC | 434 ms
82,644 KB |
ソースコード
import heapq class DeletableHeapq: def __init__(self, lst=None, reverse=False): if reverse: self.pm = -1 else: self.pm = 1 if lst is None: self.hq = [] else: self.hq = [self.pm * x for x in lst] heapq.heapify(self.hq) self.tot = sum(self.hq) * self.pm self.cnt = {} for x in self.hq: self.cnt[x] = self.cnt.get(x, 0) + 1 self.length = len(self.hq) def __bool__(self): return bool(self.hq) def __len__(self): return self.length @property def sum(self): return self.tot def top(self): if self.hq: return self.hq[0] * self.pm else: return None def __getitem__(self, i): # 先頭要素にアクセスしたいときのみ assert i == 0 return self.top() def push(self, x): self.length += 1 self.cnt[x * self.pm] = self.cnt.get(x * self.pm, 0) + 1 self.tot += x heapq.heappush(self.hq, x * self.pm) def pop(self): if not self.hq: return None self.length -= 1 x = heapq.heappop(self.hq) self.cnt[x] -= 1 self.tot -= x * self.pm self._delete() return x * self.pm def remove(self, x): if self.cnt.get(x * self.pm, 0) == 0: return False self.length -= 1 self.cnt[x * self.pm] -= 1 self.tot -= x self._delete() return True def _delete(self): while self.hq and self.cnt.get(self.hq[0], 0) == 0: heapq.heappop(self.hq) h, w = map(int, input().split()) S = [input() for _ in range(h)] dp = [0] * w for i in range(h - 1, -1, -1): add = [[] for _ in range(w)] rem = [[] for _ in range(w)] L = [0] * w l = 0 for j in range(w): if S[i][j] == "#": l = j + 1 L[j] = l R = [0] * w r = w - 1 for j in range(w - 1, -1, -1): if S[i][j] == "#": r = j - 1 R[j] = r for j in range(w): if S[i][j] == "#": continue l = max(L[j], j - dp[j]) r = min(R[j], j + dp[j]) add[l].append(dp[j]) rem[r].append(dp[j]) hq = DeletableHeapq() hq.push(1 << 30) dp = [1 << 30] * w for j in range(w): for a in add[j]: hq.push(a) dp[j] = hq[0] for a in rem[j]: hq.remove(a) for j in range(1, w): dp[j] = min(dp[j], dp[j - 1] + 1) for j in range(w - 2, -1, -1): dp[j] = min(dp[j], dp[j + 1] + 1) for j in range(w): if S[i][j] == "#": dp[j] = 1 << 30 print(*dp, sep="\n")