結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | roaris |
提出日時 | 2022-05-20 21:25:07 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,472 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 81,656 KB |
実行使用メモリ | 217,968 KB |
最終ジャッジ日時 | 2023-10-20 11:40:48 |
合計ジャッジ時間 | 12,570 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
55,512 KB |
testcase_01 | AC | 42 ms
55,512 KB |
testcase_02 | AC | 42 ms
55,512 KB |
testcase_03 | AC | 372 ms
165,380 KB |
testcase_04 | AC | 362 ms
165,572 KB |
testcase_05 | AC | 42 ms
55,520 KB |
testcase_06 | AC | 322 ms
143,456 KB |
testcase_07 | AC | 286 ms
217,968 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 334 ms
160,324 KB |
testcase_12 | AC | 341 ms
160,344 KB |
testcase_13 | AC | 379 ms
164,372 KB |
testcase_14 | AC | 385 ms
163,856 KB |
testcase_15 | WA | - |
testcase_16 | AC | 352 ms
144,216 KB |
testcase_17 | WA | - |
testcase_18 | AC | 366 ms
166,092 KB |
testcase_19 | WA | - |
testcase_20 | AC | 295 ms
191,364 KB |
testcase_21 | AC | 384 ms
164,780 KB |
testcase_22 | AC | 404 ms
164,716 KB |
ソースコード
import sys input = sys.stdin.readline from collections import * class Unionfind: def __init__(self, n): self.par = [-1]*n self.rank = [1]*n def root(self, x): r = x while not self.par[r]<0: r = self.par[r] t = x while t!=r: tmp = t t = self.par[t] self.par[tmp] = r return r def unite(self, x, y): rx = self.root(x) ry = self.root(y) if rx==ry: return if self.rank[rx]<=self.rank[ry]: self.par[ry] += self.par[rx] self.par[rx] = ry if self.rank[rx]==self.rank[ry]: self.rank[ry] += 1 else: self.par[rx] += self.par[ry] self.par[ry] = rx def is_same(self, x, y): return self.root(x)==self.root(y) def count(self, x): return -self.par[self.root(x)] N = int(input()) X = list(map(int, input().split())) d = defaultdict(lambda: -1) for i in range(N): d[X[i]] = i A = list(map(int, input().split())) uf = Unionfind(N) for i in range(N): if d[X[i]+A[i]]!=-1: uf.unite(i, d[X[i]+A[i]]) if d[X[i]-A[i]]!=-1: uf.unite(i, d[X[i]-A[i]]) res = defaultdict(int) for i in range(N): res[uf.root(i)] = max(res[uf.root(i)], X[i]+A[i]) for i in range(N): print(res[uf.root(i)]-X[i])