結果

問題 No.1950 片道きゃっちぼーる
ユーザー otoshigootoshigo
提出日時 2022-05-21 00:11:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 611 ms / 3,000 ms
コード長 1,521 bytes
コンパイル時間 5,032 ms
コンパイル使用メモリ 281,180 KB
実行使用メモリ 57,436 KB
最終ジャッジ日時 2023-10-20 15:05:42
合計ジャッジ時間 12,849 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 291 ms
57,436 KB
testcase_04 AC 295 ms
57,436 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 348 ms
57,436 KB
testcase_07 AC 204 ms
32,400 KB
testcase_08 AC 311 ms
32,400 KB
testcase_09 AC 268 ms
45,004 KB
testcase_10 AC 226 ms
33,168 KB
testcase_11 AC 246 ms
33,032 KB
testcase_12 AC 229 ms
33,032 KB
testcase_13 AC 313 ms
36,808 KB
testcase_14 AC 341 ms
38,704 KB
testcase_15 AC 608 ms
51,100 KB
testcase_16 AC 354 ms
47,932 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 252 ms
35,476 KB
testcase_19 AC 611 ms
46,084 KB
testcase_20 AC 212 ms
32,396 KB
testcase_21 AC 327 ms
38,756 KB
testcase_22 AC 333 ms
38,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
using mint = atcoder::modint998244353;
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,a,b) for (int i = a; i < b; i++)
#define rrep2(i,a,b) for (int i = a-1; i >= b; i--)
#define rep3(i,a,b,c) for (int i = a; i < b; i+=c)
#define rrep3(i,a,b,c) for (int i = a-1; i >= b; i-=c)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int n,X[200010],A[200010];
map<int,vector<int>>g;
bool flag[200010];

void dfs(int x,int y,vector<int>&Ans){
    for(auto i:g[x]){
        if(flag[i])continue;
        flag[i]=true;
        Ans[i]=A[y]+X[y]-X[i];
        dfs(i,y,Ans);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    map<int,int>mp;
    rep(i,n){
        cin>>X[i];
        mp[X[i]]=i;
    }
    vector<pair<int,int>>vp;
    rep(i,n){
        cin>>A[i];
        vp.push_back(make_pair(A[i]+X[i],i));
        if(mp.count(X[i]-A[i]))g[mp[X[i]-A[i]]].push_back(i);
        if(mp.count(X[i]+A[i]))g[mp[X[i]+A[i]]].push_back(i);
    }
    sort(rall(vp));
    vector<int>Ans(n);
    for(auto[c,x]:vp){
        if(flag[x])continue;
        Ans[x]=A[x];
        flag[x]=true;
        dfs(x,x,Ans);
    }
    rep(i,n)cout<<Ans[i]<<"\n";
}
0