結果
問題 | No.1950 片道きゃっちぼーる |
ユーザー | atcoder8 |
提出日時 | 2022-09-10 17:54:59 |
言語 | Rust (1.77.0) |
結果 |
AC
|
実行時間 | 477 ms / 3,000 ms |
コード長 | 1,979 bytes |
コンパイル時間 | 2,298 ms |
コンパイル使用メモリ | 146,716 KB |
実行使用メモリ | 22,596 KB |
最終ジャッジ日時 | 2023-08-17 21:58:30 |
合計ジャッジ時間 | 11,860 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,940 KB |
testcase_01 | AC | 1 ms
5,016 KB |
testcase_02 | AC | 1 ms
5,012 KB |
testcase_03 | AC | 334 ms
22,212 KB |
testcase_04 | AC | 340 ms
22,240 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 330 ms
22,244 KB |
testcase_07 | AC | 302 ms
13,216 KB |
testcase_08 | AC | 337 ms
13,232 KB |
testcase_09 | AC | 336 ms
22,168 KB |
testcase_10 | AC | 319 ms
16,028 KB |
testcase_11 | AC | 305 ms
17,080 KB |
testcase_12 | AC | 307 ms
16,576 KB |
testcase_13 | AC | 350 ms
19,608 KB |
testcase_14 | AC | 361 ms
22,264 KB |
testcase_15 | AC | 477 ms
22,296 KB |
testcase_16 | AC | 328 ms
22,256 KB |
testcase_17 | AC | 1 ms
4,376 KB |
testcase_18 | AC | 326 ms
17,504 KB |
testcase_19 | AC | 476 ms
22,308 KB |
testcase_20 | AC | 304 ms
13,000 KB |
testcase_21 | AC | 351 ms
22,596 KB |
testcase_22 | AC | 341 ms
22,308 KB |
ソースコード
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); } }