結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
tsubu_taiyaki
|
| 提出日時 | 2017-01-30 09:54:11 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,547 bytes |
| コンパイル時間 | 11,960 ms |
| コンパイル使用メモリ | 388,860 KB |
| 最終ジャッジ日時 | 2024-11-14 19:56:25 |
| 合計ジャッジ時間 | 12,621 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
warning: unused import: `std::cmp::*`
--> src/main.rs:4:5
|
4 | use std::cmp::*;
| ^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0782]: trait objects must include the `dyn` keyword
--> src/main.rs:7:21
|
7 | tokens: &'a mut Iterator<Item = String>,
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: add `dyn` keyword before this trait
|
7 | tokens: &'a mut dyn Iterator<Item = String>,
| +++
error[E0782]: trait objects must include the `dyn` keyword
--> src/main.rs:11:23
|
11 | fn new(i: &'a mut Iterator<Item = String>) -> Self {
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: add `dyn` keyword before this trait
|
11 | fn new(i: &'a mut dyn Iterator<Item = String>) -> Self {
| +++
For more information about this error, try `rustc --explain E0782`.
error: could not compile `main` (bin "main") due to 2 previous errors; 1 warning emitted
ソースコード
use std::io::{self, BufRead};
use std::str::FromStr;
use std::collections::*;
use std::cmp::*;
struct Parser<'a> {
tokens: &'a mut Iterator<Item = String>,
}
impl<'a> Parser<'a> {
fn new(i: &'a mut Iterator<Item = String>) -> Self {
Parser {tokens: i}
}
fn take<T: FromStr>(&mut self) -> T {
match self.tokens.next().expect("empty iterator").parse() {
Ok(x) => x,
Err(_) => panic!()
}
}
fn take_some<T: FromStr>(&mut self, n: usize) -> Vec<T> {
self.tokens.take(n).map(|s| match s.parse() { Ok(x) => x, Err(_) => panic!() } ).collect()
}
}
fn bit_count(n: i64) -> i64 {
match n {
0 => 0,
_ => 1 + bit_count(n - (n&(-n))),
}
}
fn main() {
let stdin = io::stdin();
let mut tokens = stdin.lock().lines().filter_map(|x| x.ok()).flat_map(|x| x.split_whitespace().map(|s| s.to_owned()).collect::<Vec<String>>());
let mut parser = Parser::new(&mut tokens);
let n: i64 = parser.take();
let mut v = Vec::new();
v.resize((n+1) as usize, None::<i64>);
let mut q = BinaryHeap::new();
q.push((-1i64,1i64));
while let Some((c, p)) = q.pop() {
if p <= 0 {
continue;
}
if p > n {
continue;
}
if v[p as usize].is_some() {
continue;
}
v[p as usize] = Some(c);
q.push((c-1, p + bit_count(p)));
q.push((c-1, p - bit_count(p)));
}
println!("{}", match v[n as usize] { Some(c) => -c, None => -1});
}
tsubu_taiyaki