結果

問題 No.1950 片道きゃっちぼーる
ユーザー Nzt3Nzt3
提出日時 2022-05-24 23:04:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 900 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 179,896 KB
実行使用メモリ 24,596 KB
最終ジャッジ日時 2023-10-20 18:59:05
合計ジャッジ時間 9,016 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,196 KB
testcase_01 AC 3 ms
5,196 KB
testcase_02 AC 3 ms
5,196 KB
testcase_03 AC 201 ms
21,956 KB
testcase_04 AC 204 ms
24,596 KB
testcase_05 AC 3 ms
5,192 KB
testcase_06 AC 223 ms
21,956 KB
testcase_07 AC 178 ms
21,956 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 233 ms
23,276 KB
testcase_12 AC 188 ms
22,484 KB
testcase_13 AC 225 ms
21,956 KB
testcase_14 AC 231 ms
21,956 KB
testcase_15 WA -
testcase_16 AC 228 ms
21,956 KB
testcase_17 WA -
testcase_18 AC 197 ms
21,956 KB
testcase_19 WA -
testcase_20 AC 187 ms
21,956 KB
testcase_21 AC 233 ms
22,220 KB
testcase_22 AC 230 ms
21,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

long long rt[200000];
long long getroot(long long a){
  if(rt[a]==-1)return a;
  return rt[a]=getroot(rt[a]);
}
void unite(long long a,long long 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);
  long long N;
  cin>>N;
  vector<long long>X(N),A(N);
  map<long long,long long>iru;
  for(long long i=0;i<N;i++){
    cin>>X[i];
    iru[X[i]]=i;
  }

  for(long long &i:A)cin>>i;
  for(long long 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<long long>ans(N);
  for(long long i=0;i<N;i++){
    ans[getroot(i)]=max(ans[getroot(i)],X[i]+A[i]);
  }
  for(long long i=0;i<N;i++){
    cout<<ans[getroot(i)]-X[i]<<'\n';
  }
}
0