結果
| 問題 |
No.1950 片道きゃっちぼーる
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-10 17:54:59 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 448 ms / 3,000 ms |
| コード長 | 1,979 bytes |
| コンパイル時間 | 15,427 ms |
| コンパイル使用メモリ | 386,060 KB |
| 実行使用メモリ | 22,680 KB |
| 最終ジャッジ日時 | 2024-11-26 22:41:26 |
| 合計ジャッジ時間 | 24,683 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
use std::{cmp::Reverse, collections::VecDeque};
fn main() {
let n = {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse::<usize>().unwrap()
};
let xx = {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.split_whitespace()
.map(|x| x.parse::<usize>().unwrap())
.collect::<Vec<_>>()
};
let aa = {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.split_whitespace()
.map(|x| x.parse::<usize>().unwrap())
.collect::<Vec<_>>()
};
let mut graph = vec![vec![]; n];
for curr_idx in 0..n {
if xx[curr_idx] >= aa[curr_idx] {
if let Ok(next_idx) = xx.binary_search(&(xx[curr_idx] - aa[curr_idx])) {
graph[next_idx].push(curr_idx);
}
}
if let Ok(next_idx) = xx.binary_search(&(xx[curr_idx] + aa[curr_idx])) {
graph[next_idx].push(curr_idx);
}
}
let mut sorted_indexes: Vec<usize> = (0..n).collect();
sorted_indexes.sort_unstable_by_key(|&i| Reverse(xx[i] + aa[i]));
let mut falling_positions = vec![0; n];
for &leader_idx in sorted_indexes.iter() {
if falling_positions[leader_idx] != 0 {
continue;
}
let falling_position = xx[leader_idx] + aa[leader_idx];
falling_positions[leader_idx] = falling_position;
let mut que = VecDeque::from(vec![leader_idx]);
while let Some(curr) = que.pop_front() {
for &next in graph[curr].iter() {
if falling_positions[next] == 0 {
falling_positions[next] = falling_position;
que.push_back(next);
}
}
}
}
for (&dist, &x) in falling_positions.iter().zip(xx.iter()) {
println!("{}", dist - x);
}
}