結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー |
![]() |
提出日時 | 2022-05-20 23:12:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,092 bytes |
コンパイル時間 | 2,131 ms |
コンパイル使用メモリ | 178,632 KB |
実行使用メモリ | 33,024 KB |
最終ジャッジ日時 | 2024-09-20 09:34:44 |
合計ジャッジ時間 | 7,804 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 WA * 7 |
ソースコード
#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; }