use std::collections::HashMap; use proconio::marker::Chars; fn main() { proconio::input! { n: usize, } let mut tbl = vec![-1; n + 1]; tbl[1] = 1; loop { let mut changed = false; let mut i = 1i64; while i <= n as i64 { if tbl[i as usize] != -1 { let move_ofs = i.count_ones() as i64; if i - move_ofs >= 1 && tbl[(i - move_ofs) as usize] == -1 { tbl[(i - move_ofs) as usize] = tbl[i as usize] + 1; changed = true; } if i + move_ofs <= n as i64 && tbl[(i + move_ofs) as usize] == -1 { tbl[(i + move_ofs) as usize] = tbl[i as usize] + 1; changed = true; } } i += 1; } if !changed { break; } } println!("{}", tbl[n]); } #[cfg(test)] mod test { use super::*; #[test] fn test() {} }