結果
問題 | No.2946 Puyo |
ユーザー | shimonohnishi |
提出日時 | 2024-11-03 18:03:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,188 ms / 2,000 ms |
コード長 | 2,488 bytes |
コンパイル時間 | 494 ms |
コンパイル使用メモリ | 82,616 KB |
実行使用メモリ | 279,796 KB |
最終ジャッジ日時 | 2024-11-03 18:04:10 |
合計ジャッジ時間 | 29,792 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
54,064 KB |
testcase_01 | AC | 39 ms
52,968 KB |
testcase_02 | AC | 35 ms
53,692 KB |
testcase_03 | AC | 684 ms
274,780 KB |
testcase_04 | AC | 698 ms
275,152 KB |
testcase_05 | AC | 681 ms
279,796 KB |
testcase_06 | AC | 706 ms
275,132 KB |
testcase_07 | AC | 721 ms
274,880 KB |
testcase_08 | AC | 113 ms
87,256 KB |
testcase_09 | AC | 251 ms
139,856 KB |
testcase_10 | AC | 107 ms
83,336 KB |
testcase_11 | AC | 335 ms
185,820 KB |
testcase_12 | AC | 109 ms
90,536 KB |
testcase_13 | AC | 41 ms
60,352 KB |
testcase_14 | AC | 136 ms
94,204 KB |
testcase_15 | AC | 93 ms
82,308 KB |
testcase_16 | AC | 139 ms
100,748 KB |
testcase_17 | AC | 377 ms
212,672 KB |
testcase_18 | AC | 83 ms
76,748 KB |
testcase_19 | AC | 235 ms
114,624 KB |
testcase_20 | AC | 308 ms
118,444 KB |
testcase_21 | AC | 430 ms
177,560 KB |
testcase_22 | AC | 123 ms
82,856 KB |
testcase_23 | AC | 305 ms
105,768 KB |
testcase_24 | AC | 690 ms
166,992 KB |
testcase_25 | AC | 578 ms
157,832 KB |
testcase_26 | AC | 655 ms
159,668 KB |
testcase_27 | AC | 83 ms
76,696 KB |
testcase_28 | AC | 881 ms
133,792 KB |
testcase_29 | AC | 1,188 ms
156,940 KB |
testcase_30 | AC | 682 ms
120,028 KB |
testcase_31 | AC | 997 ms
140,620 KB |
testcase_32 | AC | 965 ms
145,972 KB |
testcase_33 | AC | 766 ms
135,976 KB |
testcase_34 | AC | 1,059 ms
161,460 KB |
testcase_35 | AC | 856 ms
154,372 KB |
testcase_36 | AC | 811 ms
161,088 KB |
testcase_37 | AC | 784 ms
171,640 KB |
testcase_38 | AC | 551 ms
141,512 KB |
testcase_39 | AC | 508 ms
148,136 KB |
testcase_40 | AC | 312 ms
130,992 KB |
testcase_41 | AC | 658 ms
190,668 KB |
testcase_42 | AC | 540 ms
186,460 KB |
testcase_43 | AC | 874 ms
131,744 KB |
testcase_44 | AC | 987 ms
147,312 KB |
testcase_45 | AC | 844 ms
134,544 KB |
testcase_46 | AC | 571 ms
109,548 KB |
testcase_47 | AC | 770 ms
128,092 KB |
ソースコード
import sys import pypyjit H, W = map(int, input().split()) S = [list(input()) for _ in range(H)] pypyjit.set_param('max_unroll_recursion=-1') sys.setrecursionlimit(2000000) class dsu(): n = 1 parent_or_size = [-1 for i in range(n)] def __init__(self, N): self.n = N self.parent_or_size = [-1 for i in range(N)] def merge(self, a, b): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(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, b): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(b, self.n) return self.leader(a) == self.leader(b) def leader(self, a): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) if (self.parent_or_size[a] < 0): return a self.parent_or_size[a] = self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self, a): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf = [0 for i in range(self.n)] group_size = [0 for i in range(self.n)] for i in range(self.n): leader_buf[i] = self.leader(i) group_size[leader_buf[i]] += 1 result = [[] for i in range(self.n)] for i in range(self.n): result[leader_buf[i]].append(i) result2 = [] for i in range(self.n): if len(result[i]) > 0: result2.append(result[i]) return result2 dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]] DSU = dsu(H * W) for i in range(H): for j in range(W): if S[i][j] == '.': continue for dx, dy in dxy: ni, nj = i + dx, j + dy if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == S[i][j]: DSU.merge(i * W + j, ni * W + nj) # 連結成分のサイズが4以上の場所を.に変える for g in DSU.groups(): if len(g) < 4: continue for i in g: S[i // W][i % W] = '.' print('\n'.join([''.join(s) for s in S]))