結果

問題 No.1950 片道きゃっちぼーる
ユーザー siganaisiganai
提出日時 2022-05-21 01:21:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 822 ms / 3,000 ms
コード長 1,463 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 81,784 KB
実行使用メモリ 145,852 KB
最終ジャッジ日時 2023-10-20 15:25:28
合計ジャッジ時間 11,957 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
63,640 KB
testcase_01 AC 51 ms
63,640 KB
testcase_02 AC 50 ms
63,640 KB
testcase_03 AC 355 ms
145,604 KB
testcase_04 AC 411 ms
145,852 KB
testcase_05 AC 48 ms
63,640 KB
testcase_06 AC 326 ms
137,784 KB
testcase_07 AC 308 ms
135,240 KB
testcase_08 AC 559 ms
134,996 KB
testcase_09 AC 385 ms
144,532 KB
testcase_10 AC 406 ms
141,912 KB
testcase_11 AC 321 ms
134,784 KB
testcase_12 AC 344 ms
138,296 KB
testcase_13 AC 496 ms
143,364 KB
testcase_14 AC 494 ms
141,980 KB
testcase_15 AC 727 ms
141,916 KB
testcase_16 AC 348 ms
140,772 KB
testcase_17 AC 51 ms
63,640 KB
testcase_18 AC 406 ms
143,748 KB
testcase_19 AC 822 ms
141,904 KB
testcase_20 AC 343 ms
135,048 KB
testcase_21 AC 445 ms
145,772 KB
testcase_22 AC 472 ms
145,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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])
0