結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2019-08-14 00:45:22 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,033 bytes |
コンパイル時間 | 15,884 ms |
コンパイル使用メモリ | 379,568 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-19 13:39:47 |
合計ジャッジ時間 | 12,125 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 33 |
ソースコード
fn read<T: std::str::FromStr>() -> T {let mut s = String::new();std::io::stdin().read_line(&mut s).ok();s.trim().parse().ok().unwrap()}fn main() {let n:u32 = read();if n == 1 {println!("0");std::process::exit(0);}let mut cells = vec![];for i in 1..=n {cells.push(i.count_ones() as i32);}println!("{:?}", &cells);let max = cells.len() - 1;let mut idx = 0;let mut count = 0;loop {let speed: i32 = cells[idx];if speed + idx as i32 > max as i32 && idx as i32 - speed < 0 {println!("-1");std::process::exit(0);} else if speed + idx as i32 > max as i32 {idx -= speed as usize;} else {idx += speed as usize;}count += 1;if count > max {println!("-1");std::process::exit(0);}if idx == max {count += 1;break;}}println!("{}", count);}