結果

問題 No.1950 片道きゃっちぼーる
ユーザー houren
提出日時 2022-05-20 23:01:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,785 bytes
コンパイル時間 1,961 ms
コンパイル使用メモリ 186,496 KB
実行使用メモリ 21,544 KB
最終ジャッジ日時 2024-09-20 09:23:59
合計ジャッジ時間 8,275 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<ll,ll> mp;
    vector<ll> x(n), a(n), ans(n);
    rep(i,n) cin >> x[i];
    rep(i,n) cin >> a[i];
    rep(i,n) mp[x[i]] = i;
    vector<bool> seen(n,false);
    rep(i,n){
        if(seen[i]) continue;
        seen[i] = true;
        vector<int> td;
        ll ma = 0;
        queue<int> que;
        que.push(i);
        while(que.size()){
            int now = que.front();
            td.push_back(now);
            chmax(ma, x[now]+a[now]);
            que.pop();
            if(mp.count(x[now]+a[now])){
                int next = mp[x[now]+a[now]];
                if(seen[next]){
                    chmax(ma, ans[next] + x[next]);
                    chmax(ma, a[next] + x[next]);
                    continue;
                }
                seen[next] = true;
                que.push(next);
            }
            if(mp.count(x[now]-a[now])){
                int next = mp[x[now]-a[now]];
                if(seen[next]){
                    chmax(ma, ans[next] + x[next]);
                    chmax(ma, a[next] + x[next]);
                    continue;
                }
                seen[next] = true;
                que.push(next);
            }
        }
        for(int z:td) ans[z] = ma - x[z];
    }
    rep(i,n) cout << ans[i] << '\n';
    return 0;
}
0