結果
| 問題 |
No.1950 片道きゃっちぼーる
|
| コンテスト | |
| ユーザー |
とりゐ
|
| 提出日時 | 2022-05-20 22:30:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,400 ms / 3,000 ms |
| コード長 | 1,648 bytes |
| コンパイル時間 | 138 ms |
| コンパイル使用メモリ | 82,116 KB |
| 実行使用メモリ | 456,108 KB |
| 最終ジャッジ日時 | 2024-09-20 08:44:44 |
| 合計ジャッジ時間 | 13,446 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
import sys
sys.setrecursionlimit(10**7)
def scc(N, G, RG):
order = []
used = [0]*N
group = [None]*N
def dfs(s):
used[s] = 1
for t in G[s]:
if not used[t]:
dfs(t)
order.append(s)
def rdfs(s, col):
group[s] = col
used[s] = 1
for t in RG[s]:
if not used[t]:
rdfs(t, col)
for i in range(N):
if not used[i]:
dfs(i)
used = [0]*N
label = 0
for s in reversed(order):
if not used[s]:
rdfs(s, label)
label += 1
return label, group
# 縮約後のグラフを構築
def construct(N, G, label, group):
G0 = [set() for i in range(label)]
GP = [[] for i in range(label)]
for v in range(N):
lbs = group[v]
for w in G[v]:
lbt = group[w]
if lbs == lbt:
continue
G0[lbs].add(lbt)
GP[lbs].append(v)
return G0, GP
n=int(input())
x=list(map(int,input().split()))
a=list(map(int,input().split()))
G=[[] for i in range(n)]
RG=[[] for i in range(n)]
id={}
for i in range(n):
id[x[i]]=i
for i in range(n):
xi,ai=x[i],a[i]
if xi-ai in id:
j=id[xi-ai]
G[j].append(i)
RG[i].append(j)
if xi+ai in id:
j=id[xi+ai]
G[j].append(i)
RG[i].append(j)
label,group=scc(n,G,RG)
G0,GP=construct(n, G, label, group)
mx=[a[i]+x[i] for i in range(n)]
mx2=[0]*label
for i in range(label):
tmp=mx2[i]
for j in GP[i]:
tmp=max(tmp,mx[j])
for j in GP[i]:
mx[j]=tmp
for to in G0[i]:
mx2[to]=max(tmp,mx2[to])
for i in range(n):
print(mx[i]-x[i])
とりゐ