結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2019-08-14 00:46:16 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,003 bytes |
コンパイル時間 | 11,549 ms |
コンパイル使用メモリ | 402,260 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-19 13:40:00 |
合計ジャッジ時間 | 12,822 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 WA * 16 |
ソースコード
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);}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);}