結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | chineristAC |
提出日時 | 2022-05-20 22:58:35 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 661 ms / 3,000 ms |
コード長 | 1,958 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 81,832 KB |
実行使用メモリ | 171,616 KB |
最終ジャッジ日時 | 2023-10-20 13:51:28 |
合計ジャッジ時間 | 10,163 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
56,164 KB |
testcase_01 | AC | 48 ms
56,164 KB |
testcase_02 | AC | 48 ms
56,164 KB |
testcase_03 | AC | 315 ms
171,072 KB |
testcase_04 | AC | 401 ms
171,320 KB |
testcase_05 | AC | 48 ms
56,164 KB |
testcase_06 | AC | 283 ms
170,256 KB |
testcase_07 | AC | 246 ms
141,044 KB |
testcase_08 | AC | 486 ms
147,352 KB |
testcase_09 | AC | 322 ms
170,520 KB |
testcase_10 | AC | 399 ms
154,504 KB |
testcase_11 | AC | 281 ms
148,920 KB |
testcase_12 | AC | 311 ms
158,376 KB |
testcase_13 | AC | 423 ms
171,052 KB |
testcase_14 | AC | 420 ms
169,552 KB |
testcase_15 | AC | 661 ms
149,440 KB |
testcase_16 | AC | 299 ms
169,668 KB |
testcase_17 | AC | 48 ms
56,164 KB |
testcase_18 | AC | 397 ms
169,772 KB |
testcase_19 | AC | 660 ms
149,428 KB |
testcase_20 | AC | 276 ms
147,692 KB |
testcase_21 | AC | 365 ms
171,612 KB |
testcase_22 | AC | 371 ms
171,616 KB |
ソースコード
import sys,random,bisect from collections import deque,defaultdict import heapq from itertools import permutations from math import gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) INF = 10**17 class UnionFindVerSize(): def __init__(self, N): self._parent = [n for n in range(0, N)] self._size = [1] * N self.group = N def find_root(self, x): if self._parent[x] == x: return x self._parent[x] = self.find_root(self._parent[x]) stack = [x] while self._parent[stack[-1]]!=stack[-1]: stack.append(self._parent[stack[-1]]) for v in stack: self._parent[v] = stack[-1] return self._parent[x] def unite(self, x, y): gx = self.find_root(x) gy = self.find_root(y) if gx == gy: return self.group -= 1 if self._size[gx] < self._size[gy]: self._parent[gx] = gy self._size[gy] += self._size[gx] else: self._parent[gy] = gx self._size[gx] += self._size[gy] def get_size(self, x): return self._size[self.find_root(x)] def is_same_group(self, x, y): return self.find_root(x) == self.find_root(y) N = int(input()) X = li() A = li() dic = {x:i for i,x in enumerate(X)} back = [[] for v in range(N)] for i in range(N): if X[i]+A[i] in dic: j = dic[X[i]+A[i]] back[j].append(i) if X[i]-A[i] in dic: j = dic[X[i]-A[i]] back[j].append(i) ans = [-1 for i in range(N)] idx = [i for i in range(N)] idx.sort(key=lambda i:A[i]+X[i],reverse=True) for i in idx: if ans[i]!=-1: continue stack = [i] ans[i] = A[i]+X[i] while stack: v = stack.pop() for nv in back[v]: if ans[nv]==-1: ans[nv] = A[i]+X[i] stack.append(nv) for i in range(N): print(ans[i]-X[i])