結果
問題 | No.2946 Puyo |
ユーザー | ra5anchor |
提出日時 | 2024-10-25 22:13:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 368 ms / 2,000 ms |
コード長 | 1,968 bytes |
コンパイル時間 | 280 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 172,244 KB |
最終ジャッジ日時 | 2024-10-25 22:13:28 |
合計ジャッジ時間 | 12,813 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
55,600 KB |
testcase_01 | AC | 40 ms
54,508 KB |
testcase_02 | AC | 39 ms
55,296 KB |
testcase_03 | AC | 336 ms
171,780 KB |
testcase_04 | AC | 348 ms
172,060 KB |
testcase_05 | AC | 336 ms
172,244 KB |
testcase_06 | AC | 339 ms
172,192 KB |
testcase_07 | AC | 368 ms
171,928 KB |
testcase_08 | AC | 98 ms
80,212 KB |
testcase_09 | AC | 175 ms
102,680 KB |
testcase_10 | AC | 102 ms
79,664 KB |
testcase_11 | AC | 214 ms
120,368 KB |
testcase_12 | AC | 94 ms
80,176 KB |
testcase_13 | AC | 48 ms
64,132 KB |
testcase_14 | AC | 141 ms
83,464 KB |
testcase_15 | AC | 117 ms
78,868 KB |
testcase_16 | AC | 143 ms
85,980 KB |
testcase_17 | AC | 270 ms
127,428 KB |
testcase_18 | AC | 94 ms
77,344 KB |
testcase_19 | AC | 185 ms
92,684 KB |
testcase_20 | AC | 215 ms
93,440 KB |
testcase_21 | AC | 299 ms
117,508 KB |
testcase_22 | AC | 127 ms
81,648 KB |
testcase_23 | AC | 205 ms
92,608 KB |
testcase_24 | AC | 340 ms
122,936 KB |
testcase_25 | AC | 352 ms
116,948 KB |
testcase_26 | AC | 312 ms
120,292 KB |
testcase_27 | AC | 97 ms
77,280 KB |
testcase_28 | AC | 229 ms
104,108 KB |
testcase_29 | AC | 259 ms
118,668 KB |
testcase_30 | AC | 211 ms
98,480 KB |
testcase_31 | AC | 243 ms
108,784 KB |
testcase_32 | AC | 255 ms
111,880 KB |
testcase_33 | AC | 236 ms
105,264 KB |
testcase_34 | AC | 301 ms
119,944 KB |
testcase_35 | AC | 297 ms
116,416 KB |
testcase_36 | AC | 273 ms
118,988 KB |
testcase_37 | AC | 301 ms
126,108 KB |
testcase_38 | AC | 245 ms
111,440 KB |
testcase_39 | AC | 262 ms
112,792 KB |
testcase_40 | AC | 190 ms
97,764 KB |
testcase_41 | AC | 294 ms
130,364 KB |
testcase_42 | AC | 282 ms
125,124 KB |
testcase_43 | AC | 215 ms
103,616 KB |
testcase_44 | AC | 242 ms
108,716 KB |
testcase_45 | AC | 216 ms
103,476 KB |
testcase_46 | AC | 179 ms
93,320 KB |
testcase_47 | AC | 221 ms
102,288 KB |
ソースコード
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()) H, W = map(int, input().split()) S = [list(input().rstrip()) for _ in range(H)] uf = UnionFind(H*W) dij = [(1,0),(0,1),(-1,0),(0,-1)] for i in range(H): for j in range(W): for (di,dj) in dij: ni, nj = i+di, j+dj if ni < 0 or ni >= H or nj < 0 or nj >= W: continue if S[i][j] == S[ni][nj]: uf.union(i*W+j, (ni)*W+nj) # print(i,j,ni,nj) T = [[0]*W for _ in range(H)] for i in range(H): for j in range(W): # print(i,j,uf.size(i*H+j)) if uf.size(i*W+j) >= 4: T[i][j] = '.' else: T[i][j] = S[i][j] for i in range(H): print(''.join(T[i]))