結果

問題 No.1950 片道きゃっちぼーる
ユーザー rogi52rogi52
提出日時 2022-05-21 00:12:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 613 ms / 3,000 ms
コード長 1,276 bytes
コンパイル時間 2,604 ms
コンパイル使用メモリ 225,120 KB
実行使用メモリ 36,088 KB
最終ジャッジ日時 2023-10-20 15:06:09
合計ジャッジ時間 10,677 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 258 ms
36,088 KB
testcase_04 AC 233 ms
36,088 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 266 ms
36,088 KB
testcase_07 AC 233 ms
29,752 KB
testcase_08 AC 285 ms
29,752 KB
testcase_09 AC 262 ms
35,824 KB
testcase_10 AC 232 ms
30,612 KB
testcase_11 AC 261 ms
30,600 KB
testcase_12 AC 218 ms
30,600 KB
testcase_13 AC 289 ms
34,240 KB
testcase_14 AC 300 ms
36,088 KB
testcase_15 AC 613 ms
36,088 KB
testcase_16 AC 285 ms
36,088 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 272 ms
32,920 KB
testcase_19 AC 599 ms
36,088 KB
testcase_20 AC 232 ms
29,752 KB
testcase_21 AC 277 ms
36,088 KB
testcase_22 AC 260 ms
36,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    vector<int> X(N), A(N);
    rep(i,N) cin >> X[i];
    rep(i,N) cin >> A[i];
    map<int,int> mp;
    rep(i,N) mp[X[i]] = i;

    vector<vector<int>> G(N);
    vector<int> dp(N), deg(N, 0);
    set<pair<int,int>> se;
    rep(i,N) {
        dp[i] = X[i] + A[i];
        se.insert({X[i] + A[i], i});
        if(mp.count(X[i] + A[i])) {
            int to = mp[X[i] + A[i]];
            G[to].push_back(i);
            deg[i]++;
        }
        if(mp.count(X[i] - A[i])) {
            int to = mp[X[i] - A[i]];
            G[to].push_back(i);
            deg[i]++;
        }
    }

    while(!se.empty()) {
        queue<int> q;
        auto it = se.end(); it--;
        q.push(it->second);
        se.erase(*it);
        while(!q.empty()) {
            int from = q.front(); q.pop();
            for(int to : G[from]) {
                if(dp[to] < dp[from]) {
                    dp[to] = dp[from];
                    se.erase({X[to] + A[to], to});
                    q.push(to);
                }
            }
        }
    }

    rep(i,N) cout << dp[i] - X[i] << '\n';
}
0