結果
| 問題 |
No.1950 片道きゃっちぼーる
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-21 00:12:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 862 ms / 3,000 ms |
| コード長 | 1,276 bytes |
| コンパイル時間 | 2,466 ms |
| コンパイル使用メモリ | 217,196 KB |
| 最終ジャッジ日時 | 2025-01-29 12:15:20 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#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';
}