結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | chineristAC |
提出日時 | 2022-05-20 22:58:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 677 ms / 3,000 ms |
コード長 | 1,958 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 172,208 KB |
最終ジャッジ日時 | 2024-09-20 09:21:51 |
合計ジャッジ時間 | 10,238 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
55,936 KB |
testcase_01 | AC | 51 ms
55,936 KB |
testcase_02 | AC | 52 ms
56,320 KB |
testcase_03 | AC | 309 ms
171,832 KB |
testcase_04 | AC | 385 ms
171,808 KB |
testcase_05 | AC | 46 ms
55,808 KB |
testcase_06 | AC | 275 ms
170,756 KB |
testcase_07 | AC | 241 ms
141,484 KB |
testcase_08 | AC | 487 ms
147,900 KB |
testcase_09 | AC | 329 ms
170,764 KB |
testcase_10 | AC | 393 ms
154,804 KB |
testcase_11 | AC | 277 ms
149,292 KB |
testcase_12 | AC | 308 ms
158,592 KB |
testcase_13 | AC | 427 ms
171,740 KB |
testcase_14 | AC | 415 ms
170,184 KB |
testcase_15 | AC | 677 ms
149,932 KB |
testcase_16 | AC | 291 ms
170,464 KB |
testcase_17 | AC | 47 ms
55,936 KB |
testcase_18 | AC | 390 ms
170,156 KB |
testcase_19 | AC | 655 ms
150,028 KB |
testcase_20 | AC | 266 ms
148,100 KB |
testcase_21 | AC | 364 ms
172,208 KB |
testcase_22 | AC | 368 ms
172,012 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])