結果

問題 No.1950 片道きゃっちぼーる
ユーザー siganaisiganai
提出日時 2022-05-21 00:02:09
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,532 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 81,472 KB
実行使用メモリ 198,124 KB
最終ジャッジ日時 2023-10-20 14:56:17
合計ジャッジ時間 12,848 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
65,504 KB
testcase_01 AC 51 ms
65,504 KB
testcase_02 AC 51 ms
65,504 KB
testcase_03 AC 460 ms
198,124 KB
testcase_04 WA -
testcase_05 AC 53 ms
65,504 KB
testcase_06 AC 452 ms
192,204 KB
testcase_07 AC 362 ms
160,704 KB
testcase_08 AC 706 ms
154,576 KB
testcase_09 AC 508 ms
193,048 KB
testcase_10 AC 533 ms
182,900 KB
testcase_11 AC 445 ms
182,020 KB
testcase_12 AC 449 ms
185,388 KB
testcase_13 AC 613 ms
178,384 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 485 ms
195,476 KB
testcase_17 AC 51 ms
65,496 KB
testcase_18 AC 520 ms
158,868 KB
testcase_19 WA -
testcase_20 AC 407 ms
163,612 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

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])
'''
class SCC:
    def __init__(self,n):
        self.n = n
        self.edges = []
 
    def add_edge(self,a,b):
        self.edges.append((a,b))
 
    def scc(self):
        n = self.n
        counter = [0]*(n+1)
        elist = [0]*len(self.edges)
        for x,y in self.edges:
            counter[x+1] += 1
        for x in range(n):
            counter[x+1] += counter[x]
        start = counter[:]
        for x,y in self.edges:
            elist[counter[x]] = y
            counter[x] += 1
 
        k = 0
        low = [0]*n
        num = [-1]*n
        pre = [None]*n
        visited = []
        q = []
        sccs = []
        for x in range(n):
            if num[x] < 0:
                q.append(x)
                q.append(x)
                while q:
                    x = q.pop()
                    if num[x] < 0:
                        low[x] = num[x] = k
                        k += 1
                        visited.append(x)
                        for i in range(start[x],start[x+1]):
                            y = elist[i]
                            if num[y] < 0:
                                q.append(y)
                                q.append(y)
                                pre[y] = x
                            else:
                                low[x] = min(low[x],num[y])
                    else:
                        if low[x] == num[x]:
                            scc = []
                            while 1:
                                y = visited.pop()
                                num[y] = n
                                scc.append(y)
                                if x == y:
                                    break
                            sccs.append(scc)
                        y = pre[x]
                        if y is not None:
                            low[y] = min(low[y],low[x])
        return sccs[::-1]
scc = SCC(n)
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]:
        scc.add_edge(i,idx-1)
        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)
        scc.add_edge(i,idx-1)
tab = scc.scc()
pos = [0] * n
for i in range(len(tab)):
    for j in tab[i]:
        pos[j] = i
p = [i for i in range(n)]
p.sort(key = lambda y:x[y]+a[y],reverse = True)
ans = [-1] * n
used = [0] * len(tab)
for pp in p:
    if used[pos[pp]]:continue
    ans[pp] = max(ans[pp],x[pp] + a[pp])
    for j in tab[pos[pp]]:
        ans[j] = max(ans[j],ans[pp])
        for nex in g[j]:
            ans[nex] = max(ans[nex],ans[pp])
    used[pos[pp]] = 1
for i in range(n):
    print(ans[i]-x[i])
0