結果
| 問題 | No.1950 片道きゃっちぼーる |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-21 01:23:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 451 ms / 3,000 ms |
| コード長 | 1,484 bytes |
| 記録 | |
| コンパイル時間 | 2,471 ms |
| コンパイル使用メモリ | 214,548 KB |
| 最終ジャッジ日時 | 2025-01-29 12:27:46 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
V<ll> X(N), A(N);
rep(i, N) cin >> X[i];
rep(i, N) cin >> A[i];
map<ll, int> mp;
rep(i, N) mp[X[i]] = i;
V<V<int>> G(N);
rep(i, N) {
if (mp.count(X[i] + A[i])) {
// i -> mp[X[i] + A[i]] に行ける
G[mp[X[i] + A[i]]].push_back(i);
}
if (mp.count(X[i] - A[i])) {
G[mp[X[i] - A[i]]].push_back(i);
}
}
V<ll> ans(N);
rep(i, N) ans[i] = X[i] + A[i];
V<int> seen(N, 0);
V<int> ind(N);
iota(ind.begin(), ind.end(), 0);
sort(ind.begin(), ind.end(), [&](int i, int j) { return ans[i] < ans[j]; });
for (int i = N - 1; i >= 0; i--) {
int cv = ind[i];
if (seen[cv]) continue;
queue<int> que;
que.push(cv);
while (!que.empty()) {
int v = que.front();
que.pop();
if (seen[v]) continue;
seen[v] = 1;
for (auto nx : G[v]) {
ans[nx] = max(ans[nx], ans[v]);
if (seen[nx] == 0) {
que.push(nx);
}
}
}
}
rep(i, N) cout << ans[i] - X[i] << '\n';
return 0;
}