結果
問題 | No.697 池の数はいくつか |
ユーザー | rlangevin |
提出日時 | 2023-01-26 20:28:43 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,439 bytes |
コンパイル時間 | 1,109 ms |
コンパイル使用メモリ | 83,272 KB |
実行使用メモリ | 306,264 KB |
最終ジャッジ日時 | 2023-09-09 19:19:36 |
合計ジャッジ時間 | 16,008 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 79 ms
71,056 KB |
testcase_01 | AC | 76 ms
71,320 KB |
testcase_02 | AC | 78 ms
70,912 KB |
testcase_03 | AC | 73 ms
71,052 KB |
testcase_04 | AC | 75 ms
71,196 KB |
testcase_05 | AC | 76 ms
71,216 KB |
testcase_06 | AC | 74 ms
71,212 KB |
testcase_07 | AC | 74 ms
71,248 KB |
testcase_08 | AC | 74 ms
71,052 KB |
testcase_09 | AC | 74 ms
71,404 KB |
testcase_10 | AC | 72 ms
71,044 KB |
testcase_11 | AC | 75 ms
70,920 KB |
testcase_12 | AC | 75 ms
71,212 KB |
testcase_13 | AC | 73 ms
71,216 KB |
testcase_14 | AC | 75 ms
71,348 KB |
testcase_15 | AC | 73 ms
71,260 KB |
testcase_16 | AC | 72 ms
71,084 KB |
testcase_17 | AC | 75 ms
70,952 KB |
testcase_18 | AC | 76 ms
71,276 KB |
testcase_19 | AC | 75 ms
71,188 KB |
testcase_20 | AC | 74 ms
71,084 KB |
testcase_21 | AC | 74 ms
71,344 KB |
testcase_22 | AC | 75 ms
71,196 KB |
testcase_23 | AC | 75 ms
71,260 KB |
testcase_24 | AC | 391 ms
102,820 KB |
testcase_25 | AC | 351 ms
103,640 KB |
testcase_26 | AC | 354 ms
103,368 KB |
testcase_27 | AC | 375 ms
103,816 KB |
testcase_28 | AC | 354 ms
103,376 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) pre = [0] * W cnt = 0 for i in range(H): L = list(map(int, input().split())) for j in range(W - 1): if L[j] and L[j + 1]: if U.is_same(i * W + j, i * W + j + 1): continue U.union(i * W + j, i * W + j + 1) cnt -= 1 for j in range(W): if L[j]: cnt += 1 if pre[j] and L[j]: if U.is_same((i - 1) * W + j, i * W + j): continue U.union((i - 1) * W + j, i * W + j) cnt -= 1 L, pre = pre, L print(cnt)