結果
| 問題 |
No.1950 片道きゃっちぼーる
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-24 22:55:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 815 bytes |
| コンパイル時間 | 1,765 ms |
| コンパイル使用メモリ | 179,400 KB |
| 実行使用メモリ | 18,304 KB |
| 最終ジャッジ日時 | 2024-09-20 14:33:54 |
| 合計ジャッジ時間 | 8,635 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 6 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int rt[200000];
int getroot(int a){
if(rt[a]==-1)return a;
else return rt[a]=getroot(rt[a]);
}
void unite(int a,int b){
a=getroot(a),b=getroot(b);
if(a!=b){
rt[a]=b;
}
}
int main(){
fill(rt,rt+200000,-1);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
vector<int>X(N),A(N);
map<int,int>iru;
for(int i=0;i<N;i++){
cin>>X[i];
iru[X[i]]=i;
}
for(int &i:A)cin>>i;
for(int i=0;i<N;i++){
if(iru.find(X[i]+A[i])!=iru.end()){
unite(iru[X[i]+A[i]],i);
}
if(iru.find(X[i]-A[i])!=iru.end()){
unite(iru[X[i]-A[i]],i);
}
}
vector<int>ans(N);
for(int i=0;i<N;i++){
ans[getroot(i)]=max(ans[getroot(i)],X[i]+A[i]);
}
for(int i=0;i<N;i++){
cout<<ans[getroot(i)]-X[i]<<'\n';
}
}