結果
| 問題 | No.6 使いものにならないハッシュ |
| コンテスト | |
| ユーザー |
tsubu_taiyaki
|
| 提出日時 | 2017-02-04 09:12:03 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,390 bytes |
| 記録 | |
| コンパイル時間 | 490 ms |
| コンパイル使用メモリ | 151,956 KB |
| 最終ジャッジ日時 | 2026-05-10 04:35:46 |
| 合計ジャッジ時間 | 1,691 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
error[E0782]: expected a type, found a trait
--> src/main.rs:9:21
|
9 | tokens: &'a mut Iterator<Item = String>,
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: you can add the `dyn` keyword if you want a trait object
|
9 | tokens: &'a mut dyn Iterator<Item = String>,
| +++
error[E0782]: expected a type, found a trait
--> src/main.rs:14:23
|
14 | fn new(i: &'a mut Iterator<Item = String>) -> Self {
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: use a new generic type parameter, constrained by `Iterator<Item = String>`
|
14 - fn new(i: &'a mut Iterator<Item = String>) -> Self {
14 + fn new<T: Iterator<Item = String>>(i: &'a mut T) -> Self {
|
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
|
14 | fn new(i: &'a mut impl Iterator<Item = String>) -> Self {
| ++++
help: alternatively, use a trait object to accept any type that implements `Iterator<Item = String>`, accessing its methods at runtime using dynamic dispatch
|
14 | fn new(i: &'a mut dyn Iterator<Item = String>) -> Self {
| +++
error[E0282]: type annotations needed
--> src/main.rs:25:34
|
25 | self.tokens.take(n).map(|s| match s.parse() { Ok(x) => x, Err(_) => panic!() } ).collect()
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
25 | self.tokens.take(n).map(|s: /* Type */| match s.parse() { Ok(x) => x, Err(_) => panic!() } ).collect()
| ++++++++++++
Some errors have detailed explanations: E0282, E0782.
For more information about an error, try `rustc --explain E0282`.
error: could not compile `main` (bin "main") due to 3 previous errors
ソースコード
#![allow(unused_imports)]
use std::io::{self, BufRead};
use std::str::FromStr;
use std::collections::*;
use std::cmp::*;
struct Parser<'a> {
tokens: &'a mut Iterator<Item = String>,
}
#[allow(dead_code)]
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()
}
}
//sieve[k] is true if k is a prime
//[0, n)
fn sieve_of_eratosthenes(n: u64) -> Vec<bool> {
let mut v = vec![true; n as usize];
v[0] = false;
v[1] = false;
for i in 2..n {
if !v[i as usize] {
continue;
}
let mut j = 2*i;
while j < n {
v[j as usize] = false;
j += i;
}
}
v
}
fn calc_hash(n: u64) -> u8 {
if n >= 10 {
let mut t = 0;
let mut m = n;
while m > 0 {
t += m % 10;
m /= 10;
}
calc_hash(t)
} else {
n as u8
}
}
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 k: u64 = parser.take();
let n: u64 = parser.take();
let sieve = sieve_of_eratosthenes(n+1);
let p: Vec<u64> = sieve.into_iter().zip(0..n+1).filter(|x| x.0).filter(|x| x.1 >= k).map(|x| x.1).collect();
let mut c = vec![0; 10];
let mut l = 0;
let mut u = 0;
let mut ans_len = 0;
let mut ans = 0;
while l < p.len() && u < p.len() + 1 {
match c.clone().into_iter().max() {
Some(x) if x >= 2 => {
c[calc_hash(p[l]) as usize] -= 1;
l += 1;
},
_ => {
if ans_len <= u-l {
ans = p[l];
ans_len = u-l;
}
if u < p.len() {
c[calc_hash(p[u]) as usize] += 1;
}
u += 1;
}
};
}
println!("{}", ans);
}
tsubu_taiyaki