結果
問題 | No.2946 Puyo |
ユーザー | nikoro256 |
提出日時 | 2024-10-25 21:25:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 804 ms / 2,000 ms |
コード長 | 1,977 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 82,764 KB |
実行使用メモリ | 124,088 KB |
最終ジャッジ日時 | 2024-10-25 21:26:15 |
合計ジャッジ時間 | 18,533 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
54,644 KB |
testcase_01 | AC | 39 ms
55,196 KB |
testcase_02 | AC | 39 ms
54,820 KB |
testcase_03 | AC | 381 ms
124,088 KB |
testcase_04 | AC | 334 ms
123,384 KB |
testcase_05 | AC | 332 ms
123,764 KB |
testcase_06 | AC | 365 ms
123,780 KB |
testcase_07 | AC | 350 ms
123,816 KB |
testcase_08 | AC | 105 ms
77,580 KB |
testcase_09 | AC | 189 ms
91,652 KB |
testcase_10 | AC | 105 ms
79,496 KB |
testcase_11 | AC | 214 ms
99,220 KB |
testcase_12 | AC | 108 ms
78,884 KB |
testcase_13 | AC | 47 ms
62,828 KB |
testcase_14 | AC | 135 ms
79,860 KB |
testcase_15 | AC | 115 ms
77,260 KB |
testcase_16 | AC | 162 ms
82,216 KB |
testcase_17 | AC | 282 ms
101,664 KB |
testcase_18 | AC | 102 ms
76,808 KB |
testcase_19 | AC | 204 ms
84,308 KB |
testcase_20 | AC | 254 ms
86,692 KB |
testcase_21 | AC | 307 ms
94,916 KB |
testcase_22 | AC | 135 ms
78,924 KB |
testcase_23 | AC | 240 ms
84,776 KB |
testcase_24 | AC | 473 ms
95,584 KB |
testcase_25 | AC | 395 ms
93,624 KB |
testcase_26 | AC | 425 ms
95,352 KB |
testcase_27 | AC | 101 ms
76,988 KB |
testcase_28 | AC | 579 ms
85,384 KB |
testcase_29 | AC | 804 ms
89,208 KB |
testcase_30 | AC | 463 ms
83,900 KB |
testcase_31 | AC | 591 ms
86,704 KB |
testcase_32 | AC | 627 ms
87,264 KB |
testcase_33 | AC | 476 ms
86,364 KB |
testcase_34 | AC | 624 ms
90,580 KB |
testcase_35 | AC | 533 ms
89,348 KB |
testcase_36 | AC | 534 ms
91,348 KB |
testcase_37 | AC | 487 ms
94,828 KB |
testcase_38 | AC | 354 ms
91,860 KB |
testcase_39 | AC | 369 ms
92,352 KB |
testcase_40 | AC | 237 ms
87,908 KB |
testcase_41 | AC | 391 ms
100,260 KB |
testcase_42 | AC | 388 ms
100,120 KB |
testcase_43 | AC | 529 ms
84,636 KB |
testcase_44 | AC | 705 ms
86,960 KB |
testcase_45 | AC | 558 ms
85,264 KB |
testcase_46 | AC | 414 ms
81,936 KB |
testcase_47 | AC | 571 ms
84,992 KB |
ソースコード
from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): way=[] while True: if self.parents[x] < 0: break else: way.append(x) x=self.parents[x] for w in way: self.parents[w]=x return x def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) def csv(x,y): return x*W+y H,W=map(int,input().split()) G=[] uf=UnionFind(H*W) for _ in range(H): G.append(input()) for i in range(H): for j in range(W): for d in [[1,0],[-1,0],[0,1],[0,-1]]: x=i+d[0] y=j+d[1] if 0<=x<H and 0<=y<W: if G[i][j] == G[x][y]: uf.union(csv(i,j),csv(x,y)) ans=[] for i in range(H): ans.append([]) for j in range(W): if uf.size(csv(i,j))>=4: ans[-1].append('.') else: ans[-1].append(G[i][j]) for g in ans: print(''.join(g))