結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2024-08-15 17:00:26 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 512 bytes |
コンパイル時間 | 11,162 ms |
コンパイル使用メモリ | 383,124 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-08-15 17:00:39 |
合計ジャッジ時間 | 12,298 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
use std::collections::VecDeque;fn main() {let mut s = String::new();std::io::stdin().read_line(&mut s).ok();let n: usize = s.trim().parse().unwrap();let (mut d, mut q) = (vec![-1; n + 1], VecDeque::from([1usize]));d[1] = 1;while !q.is_empty() {let i = q.pop_front().unwrap();let c = i.count_ones() as usize;if i + c <= n && d[i + c] == -1 {d[i + c] = d[i] + 1;q.push_back(i + c)}if d[i - c] == -1 {d[i - c] = d[i] + 1;q.push_back(i - c)}}println!("{}", d[n])}