結果

問題 No.1950 片道きゃっちぼーる
ユーザー shinchanshinchan
提出日時 2022-05-20 22:56:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 888 ms / 3,000 ms
コード長 1,490 bytes
コンパイル時間 2,908 ms
コンパイル使用メモリ 229,120 KB
実行使用メモリ 49,252 KB
最終ジャッジ日時 2023-10-20 13:49:09
合計ジャッジ時間 15,534 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 509 ms
49,252 KB
testcase_04 AC 510 ms
49,252 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 541 ms
49,252 KB
testcase_07 AC 468 ms
38,428 KB
testcase_08 AC 503 ms
38,428 KB
testcase_09 AC 521 ms
46,036 KB
testcase_10 AC 501 ms
41,860 KB
testcase_11 AC 536 ms
42,124 KB
testcase_12 AC 490 ms
42,124 KB
testcase_13 AC 549 ms
43,972 KB
testcase_14 AC 556 ms
45,028 KB
testcase_15 AC 888 ms
47,668 KB
testcase_16 AC 550 ms
46,876 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 504 ms
41,596 KB
testcase_19 AC 861 ms
46,612 KB
testcase_20 AC 478 ms
38,428 KB
testcase_21 AC 552 ms
44,764 KB
testcase_22 AC 544 ms
44,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

void chmax(ll &a, ll b) { a = max(a, b); }
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false); 
    ll n;
    cin >> n;
    vector<ll> a(n), x(n);
    rep(i, n) cin >> x[i];
    rep(i, n) cin >> a[i];
    vector<ll> dist(n, -1);
    vector<pair<ll, ll>> v;
    map<ll, int> mp;
    set<ll> s;
    rep(i, n) {
        v.push_back({a[i] + x[i], i});
        mp[x[i]] = i;
        s.insert(x[i]);
    }
    sort(be(v));
    reverse(be(v));
    vector<int> seen(n, 0);
    vector<vector<ll>> G(n);

    auto f = [&](auto&& f, ll i, ll d) -> void{
        // cout << i << " " << d << " " << x[i] << " " << a[i] << endl;
        chmax(dist[i], d);
        all(to, G[i]) {
            if(seen[to]) continue;
            seen[to] = 1;
            f(f, to, d);
        }
        return ;
    };
    rep(i, n) {
        if(s.count(x[i] - a[i])) {
            G[mp[x[i] - a[i]]].pb(i);
        }
        if(s.count(x[i] + a[i])) {
            G[mp[x[i] + a[i]]].pb(i);
        }
    }
    for(auto [e, i] : v) {
        if(seen[i]) continue;
        seen[i] = 1;
        f(f, i, e);
    }
    rep(i, n) {
        cout << dist[i] - x[i] << endl;
    }
    return 0;
}
0