結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | norioc |
提出日時 | 2022-05-20 23:25:56 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,288 bytes |
コンパイル時間 | 826 ms |
コンパイル使用メモリ | 11,872 KB |
実行使用メモリ | 106,516 KB |
最終ジャッジ日時 | 2023-10-20 14:22:00 |
合計ジャッジ時間 | 21,184 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
10,244 KB |
testcase_01 | AC | 26 ms
10,244 KB |
testcase_02 | AC | 25 ms
10,244 KB |
testcase_03 | AC | 929 ms
103,368 KB |
testcase_04 | AC | 920 ms
103,376 KB |
testcase_05 | AC | 27 ms
10,244 KB |
testcase_06 | AC | 952 ms
97,296 KB |
testcase_07 | AC | 711 ms
103,364 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 954 ms
103,636 KB |
testcase_12 | AC | 930 ms
103,636 KB |
testcase_13 | AC | 976 ms
98,548 KB |
testcase_14 | AC | 1,029 ms
98,096 KB |
testcase_15 | WA | - |
testcase_16 | AC | 1,002 ms
97,396 KB |
testcase_17 | WA | - |
testcase_18 | AC | 900 ms
103,688 KB |
testcase_19 | WA | - |
testcase_20 | AC | 797 ms
103,380 KB |
testcase_21 | AC | 1,025 ms
98,232 KB |
testcase_22 | AC | 1,016 ms
99,552 KB |
ソースコード
class UnionFind: def __init__(self, n): self.data = [-1] * (n + 1) def root(self, a: int) -> int: if self.data[a] < 0: return a self.data[a] = self.root(self.data[a]) return self.data[a] def unite(self, a: int, b: int) -> bool: pa = self.root(a) pb = self.root(b) if pa == pb: return False if self.data[pa] > self.data[pb]: pa, pb = pb, pa self.data[pa] += self.data[pb] # pa を pb をつなげる self.data[pb] = pa return True def issame(self, a: int, b: int) -> bool: return self.root(a) == self.root(b) def size(self, a: int) -> int: """a が属する集合のサイズ""" return -self.data[self.root(a)] N = int(input()) X = list(map(int, input().split())) A = list(map(int, input().split())) x2i = {} for i in range(N): x2i[X[i]] = i uf = UnionFind(N) for i, a in enumerate(A): for s in (1, -1): x = X[i] + a * s if x in x2i: j = x2i[x] uf.unite(i, j) xs = [(X[i] + A[i], i) for i in range(N)] xs.sort(reverse=True) m = {i: X[i] + A[i] for i in range(N)} for d, i in xs: root = uf.root(i) m[root] = max(m[root], m[i]) for i in range(N): print(m[uf.root(i)] - X[i])