結果

問題 No.1950 片道きゃっちぼーる
ユーザー HIcoderHIcoder
提出日時 2023-07-17 16:40:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,165 ms / 3,000 ms
コード長 2,046 bytes
コンパイル時間 2,286 ms
コンパイル使用メモリ 134,996 KB
実行使用メモリ 167,036 KB
最終ジャッジ日時 2023-10-18 00:27:36
合計ジャッジ時間 26,007 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 1,028 ms
140,516 KB
testcase_04 AC 1,061 ms
140,516 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 781 ms
88,780 KB
testcase_07 AC 1,329 ms
167,036 KB
testcase_08 AC 2,165 ms
167,036 KB
testcase_09 AC 1,088 ms
127,020 KB
testcase_10 AC 1,087 ms
116,228 KB
testcase_11 AC 1,151 ms
116,228 KB
testcase_12 AC 1,100 ms
116,228 KB
testcase_13 AC 904 ms
88,908 KB
testcase_14 AC 816 ms
75,316 KB
testcase_15 AC 1,833 ms
134,180 KB
testcase_16 AC 798 ms
79,540 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1,197 ms
144,272 KB
testcase_19 AC 1,778 ms
129,164 KB
testcase_20 AC 1,149 ms
116,228 KB
testcase_21 AC 842 ms
80,596 KB
testcase_22 AC 863 ms
80,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*

*/
#include<iostream>
#include<set> 
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include <unordered_set>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;


int main(){
    int N;
    cin>>N;

  
    vector<ll> X(N);
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>X[i];
    }
    for(int i=0;i<N;i++){
        cin>>A[i];
    }

    vector<ll> d;

    for(int i=0;i<N;i++){
        //mp[X[i]]=i;//X[i]に人iがいる
        d.push_back(X[i]);
        d.push_back(X[i]+A[i]);
        d.push_back(X[i]-A[i]);
    }

    
    set<ll> setd(d.begin(),d.end());

    map<ll,ll> mpd;
    int sz=0;
    for(ll val:setd){
        mpd[val]=sz;
        sz++;
    }

    
    map<ll,ll> rev;
    for(auto [val,idx]:mpd){
        rev[idx]=val;
    }
    



    vector<vector<int>> G(sz),rG(sz);

    
    set<pair<int,int>> edges;

    for(int i=0;i<N;i++){
        //k番目から辺を張る

        int k=mpd[X[i]];

            {
            int j=mpd[X[i]+A[i]];
            
            G[j].push_back(k);
            rG[k].push_back(j);
          
            }

            {
            int j=mpd[X[i]-A[i]];
            G[j].push_back(k);
            rG[k].push_back(j);
            }
           
            
         
    }


    vector<bool> vis(sz,false);
    vector<ll> ans(sz);

    for(int i=0;i<sz;i++){
        ans[i]=rev[i];//i番目のポジション.
    }

    auto dfs=[&](auto f,int now)->void{
        vis[now]=true;
        for(int to:G[now]){
            if(vis[to]) continue;
            ans[to]=max(ans[to],ans[now]);
            f(f,to);
        }
    };

    //インデックスが大きいほどx方向への正の方向への絶対値がおおきい
    //
    for(int i=sz-1;i>=0;i--){
        if(!vis[i]){
            dfs(dfs,i);
        }
    }

    for(int i=0;i<N;i++){
        cout<<ans[mpd[X[i]]]-X[i]<<endl;

    }



}

    
0