結果

問題 No.1950 片道きゃっちぼーる
ユーザー hourenhouren
提出日時 2022-05-20 23:12:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,092 bytes
コンパイル時間 1,991 ms
コンパイル使用メモリ 179,684 KB
実行使用メモリ 32,988 KB
最終ジャッジ日時 2023-10-20 14:04:45
合計ジャッジ時間 8,632 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,788 KB
testcase_01 AC 5 ms
7,788 KB
testcase_02 AC 5 ms
7,788 KB
testcase_03 AC 210 ms
32,988 KB
testcase_04 WA -
testcase_05 AC 5 ms
7,788 KB
testcase_06 AC 232 ms
32,988 KB
testcase_07 AC 177 ms
20,316 KB
testcase_08 AC 189 ms
20,316 KB
testcase_09 WA -
testcase_10 AC 186 ms
20,316 KB
testcase_11 AC 228 ms
20,316 KB
testcase_12 AC 184 ms
20,316 KB
testcase_13 AC 243 ms
20,316 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 238 ms
26,652 KB
testcase_17 AC 5 ms
7,788 KB
testcase_18 AC 196 ms
20,316 KB
testcase_19 WA -
testcase_20 AC 187 ms
20,316 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

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;}
map<ll,ll> mp;
vector<ll> x(200200), a(200200), ans(200200,-1);
vector<bool> seen(200200,false);
int dfs(int now){
    if(seen[now]) return ans[now];
    seen[now] = true;
    int res = x[now] + a[now];
    if(mp.count(x[now]+a[now])){
        int z = mp[x[now]+a[now]];
        chmax(res, dfs(z));
    }
    if(mp.count(x[now]-a[now])){
        int z = mp[x[now]-a[now]];
        chmax(res, dfs(z));
    }
    return ans[now] = res;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n) cin >> x[i];
    rep(i,n) cin >> a[i];
    rep(i,n) mp[x[i]] = i;
    rep(i,n) dfs(i);
    rep(i,n) cout << ans[i]-x[i] << '\n';
    return 0;
}
0