結果
問題 | No.2946 Puyo |
ユーザー | hato336 |
提出日時 | 2024-10-25 21:23:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 412 ms / 2,000 ms |
コード長 | 2,025 bytes |
コンパイル時間 | 287 ms |
コンパイル使用メモリ | 82,440 KB |
実行使用メモリ | 141,264 KB |
最終ジャッジ日時 | 2024-10-25 21:24:11 |
合計ジャッジ時間 | 16,154 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 118 ms
85,676 KB |
testcase_01 | AC | 139 ms
85,756 KB |
testcase_02 | AC | 117 ms
85,404 KB |
testcase_03 | AC | 338 ms
141,264 KB |
testcase_04 | AC | 363 ms
140,816 KB |
testcase_05 | AC | 342 ms
140,872 KB |
testcase_06 | AC | 341 ms
140,760 KB |
testcase_07 | AC | 363 ms
141,084 KB |
testcase_08 | AC | 179 ms
93,400 KB |
testcase_09 | AC | 241 ms
107,672 KB |
testcase_10 | AC | 186 ms
92,852 KB |
testcase_11 | AC | 274 ms
117,416 KB |
testcase_12 | AC | 185 ms
93,320 KB |
testcase_13 | AC | 133 ms
89,012 KB |
testcase_14 | AC | 230 ms
96,124 KB |
testcase_15 | AC | 207 ms
92,796 KB |
testcase_16 | AC | 246 ms
99,952 KB |
testcase_17 | AC | 334 ms
120,160 KB |
testcase_18 | AC | 215 ms
90,704 KB |
testcase_19 | AC | 284 ms
103,108 KB |
testcase_20 | AC | 313 ms
107,336 KB |
testcase_21 | AC | 355 ms
116,776 KB |
testcase_22 | AC | 250 ms
93,580 KB |
testcase_23 | AC | 329 ms
105,748 KB |
testcase_24 | AC | 411 ms
123,916 KB |
testcase_25 | AC | 412 ms
120,080 KB |
testcase_26 | AC | 404 ms
123,140 KB |
testcase_27 | AC | 200 ms
91,392 KB |
testcase_28 | AC | 281 ms
115,920 KB |
testcase_29 | AC | 343 ms
126,912 KB |
testcase_30 | AC | 262 ms
110,464 KB |
testcase_31 | AC | 295 ms
120,028 KB |
testcase_32 | AC | 312 ms
120,188 KB |
testcase_33 | AC | 332 ms
116,912 KB |
testcase_34 | AC | 334 ms
127,780 KB |
testcase_35 | AC | 320 ms
122,276 KB |
testcase_36 | AC | 328 ms
122,076 KB |
testcase_37 | AC | 362 ms
125,588 KB |
testcase_38 | AC | 299 ms
115,964 KB |
testcase_39 | AC | 300 ms
114,560 KB |
testcase_40 | AC | 267 ms
106,540 KB |
testcase_41 | AC | 337 ms
124,376 KB |
testcase_42 | AC | 323 ms
120,828 KB |
testcase_43 | AC | 268 ms
114,436 KB |
testcase_44 | AC | 314 ms
119,964 KB |
testcase_45 | AC | 276 ms
114,924 KB |
testcase_46 | AC | 248 ms
107,424 KB |
testcase_47 | AC | 288 ms
113,996 KB |
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) #input = sys.stdin.readline #alist = list(map(int,input().split())) 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 = collections.defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return ''.join(f'{r}: {m}' for r, m in self.all_group_members().items()) #alist = [] #s = input() h,w = map(int,input().split()) #for i in range(n): # alist.append(list(map(int,input().split()))) grid = [list(input().rstrip()) for i in range(h)] uf = UnionFind(h*w) for i in range(h): for j in range(w): if i != h-1 and grid[i][j] == grid[i+1][j]: uf.union(i*w+j,(i+1)*w+j) if j != w-1 and grid[i][j] == grid[i][j+1]: uf.union(i*w+j,i*w+j+1) for i in range(h): for j in range(w): print(grid[i][j] if uf.size(i*w+j) < 4 else '.',end='') print()