結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 3 ms
5,196 KB
testcase_02 AC 3 ms
5,196 KB
testcase_03 AC 177 ms
21,956 KB
testcase_04 WA -
testcase_05 AC 3 ms
5,192 KB
testcase_06 AC 168 ms
21,956 KB
testcase_07 AC 166 ms
21,956 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 208 ms
24,596 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 171 ms
21,956 KB
testcase_17 AC 4 ms
5,192 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 163 ms
21,956 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long rt[200000];
long long getroot(long long a){
  if(rt[a]==-1)return a;
  else 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);
    }
  }
  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