結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー |
![]() |
提出日時 | 2022-05-21 01:21:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 713 ms / 3,000 ms |
コード長 | 1,463 bytes |
コンパイル時間 | 327 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 146,584 KB |
最終ジャッジ日時 | 2024-09-20 10:56:44 |
合計ジャッジ時間 | 11,573 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect from heapq import * import functools mod=998244353 import sys input=sys.stdin.readline n=int(input()) x=list(map(int,input().split())) a=list(map(int,input().split())) ''' p = [i for i in range(n)] p.sort(key = lambda y:x[y]+a[y],reverse = True) ans = [-1] * n for pp in p: ans[pp] = x[pp] + a[pp] idx = bisect.bisect_right(x,x[pp] + a[pp]) if x[idx-1] == x[pp] + a[pp]: ans[pp] = max(ans[pp],ans[idx-1]) idx = bisect.bisect_right(x,x[pp] - a[pp]) if idx == 0: continue if x[idx-1] == x[pp] - a[pp]: ans[pp] = max(ans[pp],ans[idx-1]) for i in range(n): print(ans[i]-x[i]) ''' g = [[] for _ in range(n)] for i in range(n): idx = bisect.bisect_right(x,x[i] + a[i]) if x[idx-1] == x[i] + a[i]: g[idx-1].append(i) idx = bisect.bisect_right(x,x[i] - a[i]) if idx == 0:continue if x[idx-1] == x[i] - a[i]: g[idx-1].append(i) p = [i for i in range(n)] p.sort(key = lambda y:x[y]+a[y],reverse = True) ans = [0] * n for pp in p: if ans[pp]:continue ans[pp] = x[pp] + a[pp] que = deque([pp]) while que: now = que.pop() for nex in g[now]: if ans[nex]:continue ans[nex] = ans[pp] que.appendleft(nex) for i in range(n): print(ans[i] - x[i])