結果

問題 No.1950 片道きゃっちぼーる
ユーザー noriocnorioc
提出日時 2022-05-21 15:05:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,505 ms / 3,000 ms
コード長 749 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 11,960 KB
実行使用メモリ 149,148 KB
最終ジャッジ日時 2023-10-20 16:16:15
合計ジャッジ時間 22,280 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,144 KB
testcase_01 AC 26 ms
10,144 KB
testcase_02 AC 25 ms
10,144 KB
testcase_03 AC 942 ms
149,148 KB
testcase_04 AC 961 ms
149,144 KB
testcase_05 AC 27 ms
10,144 KB
testcase_06 AC 893 ms
142,700 KB
testcase_07 AC 759 ms
104,944 KB
testcase_08 AC 1,178 ms
105,008 KB
testcase_09 AC 936 ms
125,580 KB
testcase_10 AC 952 ms
113,300 KB
testcase_11 AC 878 ms
112,868 KB
testcase_12 AC 874 ms
112,772 KB
testcase_13 AC 990 ms
108,360 KB
testcase_14 AC 939 ms
108,152 KB
testcase_15 AC 1,505 ms
137,540 KB
testcase_16 AC 947 ms
125,780 KB
testcase_17 AC 26 ms
10,144 KB
testcase_18 AC 862 ms
104,900 KB
testcase_19 AC 1,472 ms
128,076 KB
testcase_20 AC 811 ms
105,012 KB
testcase_21 AC 884 ms
107,904 KB
testcase_22 AC 870 ms
107,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
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

# 逆辺
rev_adj = defaultdict(list)
for i in range(N):
    for s in (1, -1):
        x = X[i] + A[i] * s
        if x in x2i:
            rev_adj[x2i[x]].append(i)


memo = [0] * N


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

    for nd in rev_adj[p]:
        dfs(nd, x)


xs = [(X[i] + A[i], i) for i in range(N)]

for x, i in sorted(xs, reverse=True):
    if memo[i] != 0: continue
    dfs(i, x)

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