結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2019-10-16 22:44:39 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 913 bytes |
コンパイル時間 | 22,148 ms |
コンパイル使用メモリ | 378,932 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 05:46:43 |
合計ジャッジ時間 | 23,743 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
use std::collections::HashSet; use std::io::{self, Read}; fn read_stdin() -> Vec<String> { let mut buffer = String::new(); io::stdin().read_to_string(&mut buffer).ok(); buffer.trim().split('\n').map(|s| s.to_string()).collect() } fn main() { let input = read_stdin(); let n = *&input[0].parse::<i16>().unwrap(); let mut pos: i16 = 1; let mut memo = HashSet::new(); let mut step = 1; memo.insert(pos); while n != pos { let x: i16 = format!("{:b}", pos).chars().filter(|c| c == &'1').count() as i16; memo.insert(pos); if pos + x <= n { pos += x; } else { pos -= x; if pos <= 0 { println!("-1"); return; } } if memo.contains(&pos) { println!("-1"); return; } step += 1; } println!("{}", step); }