結果
問題 | No.3 ビットすごろく |
ユーザー | hitoyozake |
提出日時 | 2018-05-11 05:24:27 |
言語 | Rust (1.77.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 2,021 bytes |
コンパイル時間 | 5,624 ms |
コンパイル使用メモリ | 154,836 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-14 01:00:15 |
合計ジャッジ時間 | 2,405 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,384 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,380 KB |
testcase_12 | AC | 1 ms
4,376 KB |
testcase_13 | AC | 1 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,380 KB |
testcase_15 | AC | 2 ms
4,380 KB |
testcase_16 | AC | 1 ms
4,380 KB |
testcase_17 | AC | 2 ms
4,380 KB |
testcase_18 | AC | 1 ms
4,376 KB |
testcase_19 | AC | 2 ms
4,380 KB |
testcase_20 | AC | 1 ms
4,380 KB |
testcase_21 | AC | 1 ms
4,380 KB |
testcase_22 | AC | 1 ms
4,376 KB |
testcase_23 | AC | 2 ms
4,376 KB |
testcase_24 | AC | 2 ms
4,380 KB |
testcase_25 | AC | 2 ms
4,376 KB |
testcase_26 | AC | 1 ms
4,376 KB |
testcase_27 | AC | 1 ms
4,376 KB |
testcase_28 | AC | 2 ms
4,380 KB |
testcase_29 | AC | 2 ms
4,376 KB |
testcase_30 | AC | 1 ms
4,380 KB |
testcase_31 | AC | 1 ms
4,376 KB |
testcase_32 | AC | 1 ms
4,376 KB |
コンパイルメッセージ
warning: unnecessary parentheses around `while` condition --> Main.rs:32:10 | 32 | while(queue.is_empty() == false){ | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 32 - while(queue.is_empty() == false){ 32 + while queue.is_empty() == false { | warning: unnecessary parentheses around `match` scrutinee expression --> Main.rs:34:15 | 34 | match(map.get(¤t)){ | ^ ^ | help: remove these parentheses | 34 - match(map.get(¤t)){ 34 + match map.get(¤t){ | warning: unnecessary parentheses around `match` scrutinee expression --> Main.rs:51:14 | 51 | match(map.get(&next)){ | ^ ^ | help: remove these parentheses | 51 - match(map.get(&next)){ 51 + match map.get(&next){ | warning: unnecessary parentheses around `match` scrutinee expression --> Main.rs:70:14 | 70 | match(map.get(&next)){ | ^ ^ | help: remove these parentheses | 70 - match(map.get(&next)){ 70 + match map.get(&next){ | warning: unnecessary parentheses around `match` scrutinee expression --> Main.rs:89:10 | 89 | match(map.get(&n)){ | ^ ^ | help: remove these parentheses | 89 - match(map.get(&n)){ 89 + match map.get(&n){ | warning: unused variable: `x` --> Main.rs:5:9 | 5 | let x = std::io::stdin().read_line(&mut buf); | ^ help: if this is intentional, prefix it with an underscore: `_x` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `i` --> Main.rs:13:9 | 13 | for i in 0..16{ | ^ help: if this is intentional, prefix it with an underscore: `_i` warning: value assigned to `current` is never read --> Main.rs:27:13 | 27 | let mut current:u32 = 1; | ^
ソースコード
fn read_line()->String{ let mut buf = String::new(); let x = std::io::stdin().read_line(&mut buf); return buf; } fn get_bitcount(x:u32)->u32{ let mut tmp = x; let mut count = 0; for i in 0..16{ count += tmp % 2; tmp = tmp >> 1; } count } fn main() { let n = read_line().trim().parse::<u32>().unwrap(); let mut queue: std::collections::VecDeque<u32> = std::collections::VecDeque::new(); let mut map: std::collections::HashMap<u32,u32> = std::collections::HashMap::new(); queue.push_front(1); let mut current:u32 = 1; let mut step:u32 = 0; map.insert(1, 1); while(queue.is_empty() == false){ current = queue.pop_back().unwrap(); match(map.get(¤t)){ Some(_found) =>{ step = *_found; }, _ => { // never reach }, }; if current == n{ break; } let bitcount = get_bitcount(current); //get next let next = current + bitcount; let mut found = false; match(map.get(&next)){ Some(_found) =>{ found = true; }, _ => { }, }; if found == false{ map.insert(next, step+1); if next <= n { queue.push_front(next); } } let next = current - bitcount; let mut found = false; match(map.get(&next)){ Some(_found) =>{ found = true; }, _ => { }, }; if found == false{ map.insert(next, step+1); if next <= n { queue.push_front(next); } } } let mut r = -1; match(map.get(&n)){ Some(_found)=>{ r = *_found as i64; }, _ =>{ }, }; println!("{}", r); }