結果
問題 | No.2946 Puyo |
ユーザー | hiro1729 |
提出日時 | 2024-10-25 21:23:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 522 ms / 2,000 ms |
コード長 | 2,687 bytes |
コンパイル時間 | 349 ms |
コンパイル使用メモリ | 82,284 KB |
実行使用メモリ | 269,016 KB |
最終ジャッジ日時 | 2024-10-25 21:23:35 |
合計ジャッジ時間 | 16,348 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 62 ms
68,572 KB |
testcase_01 | AC | 61 ms
69,268 KB |
testcase_02 | AC | 62 ms
69,308 KB |
testcase_03 | AC | 496 ms
264,596 KB |
testcase_04 | AC | 507 ms
265,564 KB |
testcase_05 | AC | 498 ms
264,516 KB |
testcase_06 | AC | 497 ms
265,528 KB |
testcase_07 | AC | 522 ms
269,016 KB |
testcase_08 | AC | 110 ms
87,092 KB |
testcase_09 | AC | 265 ms
149,916 KB |
testcase_10 | AC | 120 ms
85,380 KB |
testcase_11 | AC | 295 ms
188,020 KB |
testcase_12 | AC | 112 ms
86,396 KB |
testcase_13 | AC | 61 ms
69,568 KB |
testcase_14 | AC | 186 ms
99,100 KB |
testcase_15 | AC | 141 ms
87,860 KB |
testcase_16 | AC | 225 ms
113,600 KB |
testcase_17 | AC | 361 ms
186,088 KB |
testcase_18 | AC | 117 ms
79,768 KB |
testcase_19 | AC | 234 ms
115,624 KB |
testcase_20 | AC | 274 ms
125,076 KB |
testcase_21 | AC | 368 ms
154,448 KB |
testcase_22 | AC | 151 ms
84,380 KB |
testcase_23 | AC | 262 ms
117,708 KB |
testcase_24 | AC | 403 ms
167,024 KB |
testcase_25 | AC | 363 ms
153,624 KB |
testcase_26 | AC | 389 ms
163,936 KB |
testcase_27 | AC | 134 ms
80,220 KB |
testcase_28 | AC | 284 ms
131,604 KB |
testcase_29 | AC | 354 ms
153,040 KB |
testcase_30 | AC | 259 ms
120,280 KB |
testcase_31 | AC | 337 ms
137,120 KB |
testcase_32 | AC | 313 ms
138,376 KB |
testcase_33 | AC | 291 ms
133,276 KB |
testcase_34 | AC | 353 ms
157,312 KB |
testcase_35 | AC | 319 ms
147,376 KB |
testcase_36 | AC | 343 ms
155,416 KB |
testcase_37 | AC | 379 ms
169,968 KB |
testcase_38 | AC | 294 ms
145,732 KB |
testcase_39 | AC | 284 ms
150,792 KB |
testcase_40 | AC | 231 ms
131,200 KB |
testcase_41 | AC | 355 ms
185,968 KB |
testcase_42 | AC | 331 ms
175,244 KB |
testcase_43 | AC | 308 ms
134,140 KB |
testcase_44 | AC | 304 ms
140,864 KB |
testcase_45 | AC | 272 ms
126,884 KB |
testcase_46 | AC | 224 ms
107,784 KB |
testcase_47 | AC | 271 ms
124,832 KB |
ソースコード
# import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') from collections import defaultdict as dd S = input R = range P = print def I(): return int(S()) def M(): return map(int, S().split()) def L(): return list(M()) def O(): return list(map(int, open(0).read().split())) def yn(b): print("Yes" if b else "No") biga = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" smaa = "abcdefghijklmnopqrstuvwxyz" ctoi = lambda c: ord(c) - ord('a') itoc = lambda i: chr(ord('a') + i) inf = 10 ** 18 mod = 998244353 def acc(a): b = [0] for i in a: b.append(b[-1] + i) return b import typing class DSU: ''' Implement (union by size) + (path halving) Reference: Zvi Galil and Giuseppe F. Italiano, Data structures and algorithms for disjoint set union problems ''' def __init__(self, n: int = 0) -> None: self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: assert 0 <= a < self._n assert 0 <= b < self._n x = self.leader(a) y = self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a: int, b: int) -> bool: assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a: int) -> int: assert 0 <= a < self._n parent = self.parent_or_size[a] while parent >= 0: if self.parent_or_size[parent] < 0: return parent self.parent_or_size[a], a, parent = ( self.parent_or_size[parent], self.parent_or_size[parent], self.parent_or_size[self.parent_or_size[parent]] ) return a def size(self, a: int) -> int: assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self) -> typing.List[typing.List[int]]: leader_buf = [self.leader(i) for i in range(self._n)] result: typing.List[typing.List[int]] = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return list(filter(lambda r: r, result)) H, W = map(int, input().split()) G = [list(input()) for _ in R(H)] uf = DSU(H * W) for i in R(H): for j in R(W - 1): if G[i][j]==G[i][j+1]: uf.merge(i*W+j,i*W+j+1) for i in R(H-1): for j in R(W): if G[i][j]==G[i+1][j]: uf.merge(i*W+j,i*W+W+j) for i in uf.groups(): if len(i)>=4: for j in i: G[j//W][j%W]='.' for i in G: P(''.join(i))