結果

問題 No.1950 片道きゃっちぼーる
ユーザー noriocnorioc
提出日時 2022-05-21 14:22:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 795 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 81,560 KB
実行使用メモリ 372,176 KB
最終ジャッジ日時 2023-10-20 16:13:28
合計ジャッジ時間 12,619 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,388 KB
testcase_01 AC 34 ms
53,388 KB
testcase_02 AC 33 ms
53,388 KB
testcase_03 AC 894 ms
365,708 KB
testcase_04 WA -
testcase_05 AC 33 ms
53,360 KB
testcase_06 AC 679 ms
372,176 KB
testcase_07 AC 272 ms
169,168 KB
testcase_08 AC 291 ms
168,560 KB
testcase_09 WA -
testcase_10 AC 342 ms
168,496 KB
testcase_11 AC 350 ms
168,496 KB
testcase_12 AC 360 ms
168,496 KB
testcase_13 AC 305 ms
144,012 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 795 ms
309,704 KB
testcase_17 AC 34 ms
53,356 KB
testcase_18 AC 328 ms
166,648 KB
testcase_19 WA -
testcase_20 AC 295 ms
168,492 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')

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

x2i = {}
for i in range(N):
    x2i[X[i]] = i

memo = [0] * N


def dfs(p, used):
    if memo[p] != 0: return memo[p]

    c = X[p] + A[p]
    for s in (1, -1):
        x = X[p] + A[p] * s
        if x in x2i:
            j = x2i[x]
            if used[j]: continue
            used[j] = True
            c = max(c, dfs(j, used))
            used[j] = False

    memo[p] = c
    #print(f'{p=} {c=} X:{c-X[p]}')
    return memo[p]


used = [False] * N
for i in range(N):
    if memo[i] != 0: continue
    used[i] = True
    dfs(i, used)
    used[i] = False

for i in range(N):
    print(memo[i] - X[i])
0