結果
問題 | No.2946 Puyo |
ユーザー | tassei903 |
提出日時 | 2024-10-25 21:27:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 547 ms / 2,000 ms |
コード長 | 2,198 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 274,740 KB |
最終ジャッジ日時 | 2024-10-25 21:28:00 |
合計ジャッジ時間 | 13,139 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,644 KB |
testcase_01 | AC | 42 ms
55,012 KB |
testcase_02 | AC | 44 ms
55,720 KB |
testcase_03 | AC | 547 ms
274,344 KB |
testcase_04 | AC | 547 ms
274,740 KB |
testcase_05 | AC | 488 ms
274,440 KB |
testcase_06 | AC | 506 ms
274,500 KB |
testcase_07 | AC | 528 ms
274,128 KB |
testcase_08 | AC | 90 ms
88,224 KB |
testcase_09 | AC | 221 ms
143,676 KB |
testcase_10 | AC | 92 ms
85,688 KB |
testcase_11 | AC | 265 ms
165,216 KB |
testcase_12 | AC | 89 ms
86,752 KB |
testcase_13 | AC | 43 ms
55,316 KB |
testcase_14 | AC | 141 ms
91,028 KB |
testcase_15 | AC | 132 ms
81,780 KB |
testcase_16 | AC | 174 ms
118,636 KB |
testcase_17 | AC | 321 ms
167,008 KB |
testcase_18 | AC | 91 ms
77,384 KB |
testcase_19 | AC | 190 ms
108,228 KB |
testcase_20 | AC | 231 ms
121,164 KB |
testcase_21 | AC | 290 ms
139,144 KB |
testcase_22 | AC | 133 ms
86,592 KB |
testcase_23 | AC | 221 ms
111,780 KB |
testcase_24 | AC | 338 ms
138,756 KB |
testcase_25 | AC | 318 ms
135,528 KB |
testcase_26 | AC | 338 ms
134,468 KB |
testcase_27 | AC | 100 ms
77,600 KB |
testcase_28 | AC | 181 ms
104,020 KB |
testcase_29 | AC | 208 ms
104,332 KB |
testcase_30 | AC | 163 ms
94,576 KB |
testcase_31 | AC | 191 ms
98,796 KB |
testcase_32 | AC | 205 ms
102,528 KB |
testcase_33 | AC | 216 ms
107,384 KB |
testcase_34 | AC | 251 ms
119,900 KB |
testcase_35 | AC | 233 ms
114,772 KB |
testcase_36 | AC | 243 ms
118,324 KB |
testcase_37 | AC | 277 ms
135,172 KB |
testcase_38 | AC | 257 ms
131,720 KB |
testcase_39 | AC | 229 ms
135,012 KB |
testcase_40 | AC | 189 ms
123,752 KB |
testcase_41 | AC | 304 ms
150,344 KB |
testcase_42 | AC | 295 ms
149,180 KB |
testcase_43 | AC | 163 ms
94,300 KB |
testcase_44 | AC | 188 ms
104,188 KB |
testcase_45 | AC | 174 ms
98,168 KB |
testcase_46 | AC | 141 ms
82,128 KB |
testcase_47 | AC | 170 ms
90,852 KB |
ソースコード
import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[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()) from math import gcd h,w = na() uf = UnionFind(h*w) s = [input() for i in range(h)] for i in range(h-1): for j in range(w): if s[i][j] == s[i+1][j]: uf.union(i*w+j, (i+1)*w+j) for i in range(h): for j in range(w-1): if s[i][j] == s[i][j+1]: uf.union(i*w+j,i*w+j+1) d = uf.all_group_members() ans = [list(s[i]) for i in range(h)] for i in d: if uf.size(i) < 4:continue for j in d[i]: x,y = divmod(j, w) ans[x][y] = "." for i in range(h): print("".join(ans[i]))