結果
| 問題 | 
                            No.3 ビットすごろく
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-04-12 19:25:30 | 
| 言語 | Rust  (1.83.0 + proconio)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,871 bytes | 
| コンパイル時間 | 22,763 ms | 
| コンパイル使用メモリ | 376,816 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-14 13:01:21 | 
| 合計ジャッジ時間 | 14,418 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge6 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 17 WA * 16 | 
ソースコード
macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}
fn rec(n: usize, i: usize, visited: &mut [bool]) -> i64 {
    visited[i] = true;
    let mut num = 0;
    for j in 0..=20 {
        if i & 1 << j != 0 {
            num += 1
        }
    }
    if i + num == n {
        1
    } else {
        let mut ret = 1 << 60;
        if i + num <= n && !visited[i + num] {
            ret = ret.min(rec(n, i + num, visited) + 1)
        }
        if 1 + num <= i && !visited[i - num] {
            ret = ret.min(rec(n, i - num, visited) + 1)
        }
        ret
    }
}
fn main() {
    let n = scan!(usize);
    let mut visited = vec![false; n + 1];
    let n = rec(n, 1, &mut visited);
    if n == 1 << 60 {
        println!("-1")
    } else {
        println!("{}", n + 1)
    }
}