結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
hitoyozake
|
| 提出日時 | 2018-05-11 05:24:27 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 2,021 bytes |
| コンパイル時間 | 12,564 ms |
| コンパイル使用メモリ | 389,396 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 09:00:30 |
| 合計ジャッジ時間 | 13,863 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
warning: unnecessary parentheses around `while` condition
--> src/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
--> src/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
--> src/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
--> src/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
--> src/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`
--> src/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`
--> src/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
--> src/main.rs:27:13
|
27 | let mut cur
ソースコード
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);
}
hitoyozake