結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | first_vil |
提出日時 | 2022-05-20 22:26:57 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,962 bytes |
コンパイル時間 | 241 ms |
コンパイル使用メモリ | 82,132 KB |
実行使用メモリ | 134,648 KB |
最終ジャッジ日時 | 2024-09-20 08:41:08 |
合計ジャッジ時間 | 9,668 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,480 KB |
testcase_01 | AC | 39 ms
52,736 KB |
testcase_02 | AC | 41 ms
52,992 KB |
testcase_03 | AC | 304 ms
131,464 KB |
testcase_04 | AC | 301 ms
131,260 KB |
testcase_05 | AC | 40 ms
52,652 KB |
testcase_06 | AC | 294 ms
114,448 KB |
testcase_07 | AC | 279 ms
133,768 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 299 ms
133,512 KB |
testcase_12 | AC | 308 ms
133,516 KB |
testcase_13 | AC | 335 ms
109,188 KB |
testcase_14 | AC | 329 ms
109,244 KB |
testcase_15 | WA | - |
testcase_16 | AC | 296 ms
110,428 KB |
testcase_17 | WA | - |
testcase_18 | AC | 330 ms
132,284 KB |
testcase_19 | WA | - |
testcase_20 | AC | 282 ms
134,264 KB |
testcase_21 | AC | 347 ms
130,492 KB |
testcase_22 | AC | 374 ms
130,684 KB |
ソースコード
import sys int1 = lambda x: int(x) - 1 # input = lambda: sys.stdin.buffer.readline() input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) i1 = lambda: int1(input()) mi = lambda: map(int, input().split()) mi1 = lambda: map(int1, input().split()) li = lambda: list(mi()) li1 = lambda: list(mi1()) lli = lambda n: [li() for _ in range(n)] INF = float("inf") mod = int(1e9 + 7) # mod = 998244353 class dsu: n = 1 parent_or_size = [-1 for i in range(n)] def __init__(self, N): self.n = N self.parent_or_size = [-1 for i in range(N)] def merge(self, a, b): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(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, b): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(b, self.n) return self.leader(a) == self.leader(b) def leader(self, a): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) if self.parent_or_size[a] < 0: return a self.parent_or_size[a] = self.leader(self.parent_or_size[a]) return self.parent_or_size[a] from bisect import bisect_left n = ii() x = li() a = li() uf = dsu(n) for i in range(n): j = bisect_left(x, x[i] - a[i]) if x[j] == x[i] - a[i]: uf.merge(i, j) j = bisect_left(x, x[i] + a[i]) if j < n and x[j] == x[i] + a[i]: uf.merge(i, j) ans = [0] * n for i in range(n): r = uf.leader(i) if ans[r] < x[i] + a[i]: ans[r] = x[i] + a[i] for i in range(n): print(ans[uf.leader(i)]-x[i])