結果
問題 | No.2999 Long Long Friedrice |
ユーザー | 遭難者 |
提出日時 | 2024-12-16 10:33:02 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,024 bytes |
コンパイル時間 | 238 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 19,700 KB |
最終ジャッジ日時 | 2024-12-23 23:31:33 |
合計ジャッジ時間 | 18,286 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 408 ms
19,320 KB |
testcase_01 | AC | 395 ms
19,316 KB |
testcase_02 | AC | 416 ms
19,460 KB |
testcase_03 | AC | 415 ms
19,508 KB |
testcase_04 | AC | 402 ms
19,504 KB |
testcase_05 | AC | 400 ms
19,572 KB |
testcase_06 | AC | 436 ms
19,444 KB |
testcase_07 | AC | 419 ms
19,572 KB |
testcase_08 | AC | 398 ms
19,700 KB |
testcase_09 | AC | 406 ms
19,532 KB |
testcase_10 | AC | 443 ms
19,320 KB |
testcase_11 | AC | 414 ms
19,252 KB |
testcase_12 | AC | 431 ms
19,264 KB |
testcase_13 | WA | - |
testcase_14 | AC | 422 ms
19,316 KB |
testcase_15 | AC | 449 ms
19,328 KB |
testcase_16 | AC | 441 ms
19,320 KB |
testcase_17 | AC | 421 ms
19,448 KB |
testcase_18 | AC | 465 ms
19,396 KB |
testcase_19 | AC | 422 ms
19,448 KB |
testcase_20 | AC | 443 ms
19,516 KB |
testcase_21 | AC | 435 ms
19,192 KB |
testcase_22 | AC | 401 ms
19,316 KB |
testcase_23 | AC | 412 ms
19,324 KB |
testcase_24 | AC | 412 ms
19,524 KB |
testcase_25 | AC | 413 ms
19,448 KB |
testcase_26 | AC | 417 ms
19,516 KB |
testcase_27 | AC | 418 ms
19,304 KB |
testcase_28 | AC | 392 ms
19,444 KB |
testcase_29 | AC | 404 ms
19,444 KB |
testcase_30 | AC | 405 ms
19,424 KB |
testcase_31 | AC | 404 ms
19,312 KB |
testcase_32 | AC | 460 ms
19,488 KB |
testcase_33 | AC | 403 ms
19,432 KB |
testcase_34 | AC | 462 ms
19,320 KB |
testcase_35 | AC | 408 ms
19,472 KB |
testcase_36 | AC | 414 ms
19,316 KB |
testcase_37 | AC | 407 ms
19,316 KB |
testcase_38 | AC | 410 ms
19,292 KB |
ソースコード
import typing class DSU: ''' Implement (union by size) + (path halving) Reference: Zvi Galil and Giuseppe F. Italiano, Data structures and algorithms for disjoint set union problems ''' def __init__(self, n: int = 0) -> None: self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: assert 0 <= a < self._n assert 0 <= 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: int, b: int) -> bool: assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a: int) -> int: assert 0 <= a < self._n parent = self.parent_or_size[a] while parent >= 0: if self.parent_or_size[parent] < 0: return parent self.parent_or_size[a], a, parent = ( self.parent_or_size[parent], self.parent_or_size[parent], self.parent_or_size[self.parent_or_size[parent]] ) return a def size(self, a: int) -> int: assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self) -> typing.List[typing.List[int]]: leader_buf = [self.leader(i) for i in range(self._n)] result: typing.List[typing.List[int]] = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return list(filter(lambda r: r, result)) n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) inf = 10**6 d = DSU(inf + 1) for i in range(n): d.merge(a[i], a[i] + b[i]) ans = 0 for i in range(inf + 1): if d.same(1, i): ans = i print(ans)