結果

問題 No.1950 片道きゃっちぼーる
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-29 16:42:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,825 ms / 3,000 ms
コード長 1,304 bytes
コンパイル時間 2,437 ms
コンパイル使用メモリ 220,964 KB
実行使用メモリ 118,608 KB
最終ジャッジ日時 2023-09-20 12:01:00
合計ジャッジ時間 23,894 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 859 ms
95,644 KB
testcase_04 AC 866 ms
95,592 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 773 ms
58,424 KB
testcase_07 AC 1,306 ms
117,712 KB
testcase_08 AC 1,825 ms
118,608 KB
testcase_09 AC 1,012 ms
89,668 KB
testcase_10 AC 937 ms
81,484 KB
testcase_11 AC 1,051 ms
81,684 KB
testcase_12 AC 967 ms
81,980 KB
testcase_13 AC 835 ms
63,060 KB
testcase_14 AC 706 ms
54,348 KB
testcase_15 AC 1,559 ms
92,612 KB
testcase_16 AC 781 ms
54,020 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 1,004 ms
103,008 KB
testcase_19 AC 1,544 ms
89,992 KB
testcase_20 AC 1,054 ms
82,336 KB
testcase_21 AC 698 ms
57,056 KB
testcase_22 AC 695 ms
56,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

map<ll, ll> mp;
vector<ll> ans;
vector<bool> vst;
vector<vector<ll>> E;

template <typename T>
map<T, T> compress(vector<T> &A){

    map<T, T> comp;
    int N = A.size(), i=0;
    for (int i=0; i<N; i++) comp[A[i]];

    for (auto &e : comp){
        e.second = i;
        i++;
    }

    return comp;
}

void dfs(int from){
    vst[from] = 1;
    for (auto to : E[from]){
        if (vst[to]) continue;
        ans[to] = max(ans[to], ans[from]);
        dfs(to);
    }
}

int main(){

    ll N, M;
    cin >> N;
    vector<ll> X(N), A(N), v;
    for (int i=0; i<N; i++) cin >> X[i];
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N; i++){
        v.push_back(X[i]);
        v.push_back(A[i]+X[i]);
        v.push_back(X[i]-A[i]);
    }
    map<ll, ll> mp = compress(v), rev;
    for (auto [x, y] : mp) rev[y] = x;
    M = mp.size();
    E.resize(M);
    ans.resize(M, -2e9);
    vst.resize(M);

    for (int i=0; i<M; i++) ans[i] = rev[i];

    for (int i=0; i<N; i++){
        E[mp[X[i]+A[i]]].push_back(mp[X[i]]);
        E[mp[X[i]-A[i]]].push_back(mp[X[i]]);
    }
    for (int i=M-1; i>=0; i--){
        if (!vst[i]) dfs(i);
    }

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

    return 0;
}
0