結果

問題 No.1950 片道きゃっちぼーる
ユーザー ああいいああいい
提出日時 2022-05-20 22:10:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 733 ms / 3,000 ms
コード長 810 bytes
コンパイル時間 1,841 ms
コンパイル使用メモリ 81,336 KB
実行使用メモリ 170,436 KB
最終ジャッジ日時 2023-10-20 12:52:19
合計ジャッジ時間 10,301 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,356 KB
testcase_01 AC 37 ms
53,356 KB
testcase_02 AC 37 ms
53,356 KB
testcase_03 AC 307 ms
170,328 KB
testcase_04 AC 366 ms
170,364 KB
testcase_05 AC 37 ms
53,360 KB
testcase_06 AC 273 ms
158,084 KB
testcase_07 AC 266 ms
167,592 KB
testcase_08 AC 593 ms
167,852 KB
testcase_09 AC 338 ms
170,436 KB
testcase_10 AC 453 ms
168,132 KB
testcase_11 AC 291 ms
167,604 KB
testcase_12 AC 299 ms
167,868 KB
testcase_13 AC 374 ms
149,468 KB
testcase_14 AC 378 ms
149,840 KB
testcase_15 AC 733 ms
168,084 KB
testcase_16 AC 276 ms
152,300 KB
testcase_17 AC 36 ms
53,360 KB
testcase_18 AC 368 ms
169,712 KB
testcase_19 AC 703 ms
168,128 KB
testcase_20 AC 276 ms
167,804 KB
testcase_21 AC 398 ms
169,296 KB
testcase_22 AC 370 ms
169,360 KB
権限があれば一括ダウンロードができます

ソースコード

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