結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-11 06:27:22 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,871 bytes |
| コンパイル時間 | 12,249 ms |
| コンパイル使用メモリ | 401,704 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-14 11:24:44 |
| 合計ジャッジ時間 | 13,156 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#[macro_export]
macro_rules! setup {
{ mut $input:ident: SplitWhitespace $(,)? } => {
use std::io::Read;
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut $input = buf.split_whitespace();
};
}
#[macro_export]
macro_rules! parse_next {
($str_iter:expr) => {
$str_iter.next().unwrap().parse().unwrap()
};
}
use std::collections::VecDeque;
fn main() {
setup! { mut input: SplitWhitespace };
let n: usize = parse_next!(input);
let ans = (|| {
let mut queue = VecDeque::new();
let mut visited = vec![false; n * 2];
{
queue.push_back(1);
visited[0] = true;
}
let mut depth = 0;
while !queue.is_empty() {
depth += 1;
let mut len = queue.len();
while len > 0 {
let i = queue.pop_front().unwrap();
if i == n {
return depth;
}
let mut children = vec![];
{
let j = i + i.count_ones() as usize;
if 1 <= j && j <= n {
children.push(j);
}
}
{
if !(i <= i.count_ones() as usize) {
let j = i - i.count_ones() as usize;
if 1 <= j && j <= n {
children.push(j);
}
}
}
for j in children.into_iter() {
if !visited[j - 1] {
queue.push_back(j);
visited[j - 1] = true;
}
}
len -= 1;
}
}
return -1;
})();
println!("{:?}", ans);
}