結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | norioc |
提出日時 | 2022-05-20 23:18:26 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,233 bytes |
コンパイル時間 | 218 ms |
コンパイル使用メモリ | 12,044 KB |
実行使用メモリ | 80,100 KB |
最終ジャッジ日時 | 2023-10-20 14:11:30 |
合計ジャッジ時間 | 19,921 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
10,240 KB |
testcase_01 | AC | 29 ms
10,240 KB |
testcase_02 | AC | 29 ms
10,240 KB |
testcase_03 | AC | 960 ms
76,688 KB |
testcase_04 | AC | 943 ms
76,700 KB |
testcase_05 | AC | 28 ms
10,240 KB |
testcase_06 | AC | 951 ms
70,692 KB |
testcase_07 | AC | 700 ms
76,700 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 929 ms
76,960 KB |
testcase_12 | AC | 927 ms
76,960 KB |
testcase_13 | AC | 940 ms
71,872 KB |
testcase_14 | AC | 1,002 ms
71,352 KB |
testcase_15 | WA | - |
testcase_16 | AC | 995 ms
70,792 KB |
testcase_17 | WA | - |
testcase_18 | AC | 880 ms
77,012 KB |
testcase_19 | WA | - |
testcase_20 | AC | 757 ms
76,704 KB |
testcase_21 | AC | 963 ms
71,552 KB |
testcase_22 | AC | 966 ms
72,872 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) m = {i: X[i] + A[i] for i in range(N)} for i in range(N): root = uf.root(i) m[root] = max(m[root], X[i] + A[i]) for i in range(N): print(m[uf.root(i)] - X[i])