結果

問題 No.1950 片道きゃっちぼーる
ユーザー ああいい
提出日時 2022-05-20 22:10:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 646 ms / 3,000 ms
コード長 810 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 82,016 KB
実行使用メモリ 171,000 KB
最終ジャッジ日時 2024-09-20 08:21:02
合計ジャッジ時間 9,853 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
X = list(map(int,input().split()))
A = list(map(int,input().split()))

d = dict()
for i,x in enumerate(X):
    d[x] = i
G = [[] for _ in range(N)]
for i in range(N):
    x = X[i]
    a = A[i]
    if x + a in d:
        G[d[x + a]].append(i)
    if x - a in d:
        G[d[x - a]].append(i)
dp = [X[i] + A[i] for i in range(N)]
top = [(X[i],A[i],i) for i in range(N)]
top.sort(key = lambda x:x[0] + x[1],reverse = True)
memo =[0] * N
stack = []
for x,a,i in top:
    if memo[i] == 0:
        stack.append(i)
        memo[i] = 1
        while stack:
            now = stack.pop()
            for j in G[now]:
                if memo[j] == 0:
                    memo[j] = 1
                    dp[j] = dp[i]
                    stack.append(j)
for i in range(N):
    print(dp[i] - X[i])
       
0