結果
問題 | No.697 池の数はいくつか |
ユーザー | rlangevin |
提出日時 | 2023-01-26 20:11:32 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,428 bytes |
コンパイル時間 | 1,971 ms |
コンパイル使用メモリ | 83,216 KB |
実行使用メモリ | 423,788 KB |
最終ジャッジ日時 | 2023-09-09 19:08:28 |
合計ジャッジ時間 | 20,958 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 80 ms
71,064 KB |
testcase_01 | AC | 78 ms
70,856 KB |
testcase_02 | AC | 78 ms
71,120 KB |
testcase_03 | AC | 78 ms
70,980 KB |
testcase_04 | AC | 78 ms
70,956 KB |
testcase_05 | AC | 78 ms
70,760 KB |
testcase_06 | AC | 79 ms
70,788 KB |
testcase_07 | AC | 78 ms
70,756 KB |
testcase_08 | AC | 80 ms
71,080 KB |
testcase_09 | AC | 77 ms
71,116 KB |
testcase_10 | AC | 82 ms
70,936 KB |
testcase_11 | AC | 80 ms
71,184 KB |
testcase_12 | AC | 78 ms
70,800 KB |
testcase_13 | AC | 79 ms
70,952 KB |
testcase_14 | AC | 79 ms
70,808 KB |
testcase_15 | AC | 78 ms
70,888 KB |
testcase_16 | AC | 79 ms
70,928 KB |
testcase_17 | AC | 79 ms
71,000 KB |
testcase_18 | AC | 79 ms
70,980 KB |
testcase_19 | AC | 80 ms
70,984 KB |
testcase_20 | AC | 80 ms
70,980 KB |
testcase_21 | AC | 80 ms
71,072 KB |
testcase_22 | AC | 78 ms
70,792 KB |
testcase_23 | AC | 80 ms
70,848 KB |
testcase_24 | AC | 427 ms
121,220 KB |
testcase_25 | AC | 420 ms
121,116 KB |
testcase_26 | AC | 411 ms
121,340 KB |
testcase_27 | AC | 431 ms
121,832 KB |
testcase_28 | AC | 416 ms
122,136 KB |
testcase_29 | MLE | - |
testcase_30 | MLE | - |
testcase_31 | MLE | - |
testcase_32 | MLE | - |
testcase_33 | MLE | - |
testcase_34 | MLE | - |
ソースコード
class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] H, W = map(int, input().split()) U = UnionFind(H * W) A = [] for i in range(H): A.append(list(map(int, input().split()))) for i in range(H - 1): for j in range(W): if not A[i][j]: continue if A[i + 1][j]: U.union(i * W + j, (i + 1) * W + j) for i in range(H): for j in range(W - 1): if not A[i][j]: continue if A[i][j + 1]: U.union(i * W + j, i * W + j + 1) S = set() for i in range(H): for j in range(W): if A[i][j]: S.add(U.find(i * W + j)) print(len(S))