結果
| 問題 | No.7 プライムナンバーゲーム |
| コンテスト | |
| ユーザー |
sino
|
| 提出日時 | 2020-03-25 21:53:44 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,950 bytes |
| 記録 | |
| コンパイル時間 | 1,136 ms |
| コンパイル使用メモリ | 144,104 KB |
| 最終ジャッジ日時 | 2026-04-17 18:23:22 |
| 合計ジャッジ時間 | 1,977 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
error: cannot explicitly dereference within an implicitly-borrowing pattern --> src/main.rs:87:22 | 87 | .filter(|(_, &flg)| flg) | ^ reference pattern not allowed when implicitly borrowing | = note: for more information, see <https://doc.rust-lang.org/reference/patterns.html#binding-modes> note: matching on a reference type with a non-reference pattern implicitly borrows the contents --> src/main.rs:87:18 | 87 | .filter(|(_, &flg)| flg) | ^^^^^^^^^ this non-reference pattern matches on a reference type `&_` help: match on the reference with a reference pattern to avoid implicitly borrowing | 87 | .filter(|&(_, &flg)| flg) | + error: could not compile `main` (bin "main") due to 1 previous error
ソースコード
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::VecDeque;
#[allow(unused_macros)]
macro_rules! read {
([$t:ty] ; $n:expr) =>
((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
($($t:ty),+ ; $n:expr) =>
((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
([$t:ty]) =>
(rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
($t:ty) =>
(rl().parse::<$t>().unwrap());
($($t:ty),*) => {{
let buf = rl();
let mut w = buf.split_whitespace();
($(w.next().unwrap().parse::<$t>().unwrap()),*)
}};
}
#[allow(dead_code)]
fn rl() -> String {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().to_owned()
}
trait IteratorExt: Iterator + Sized {
fn vec(self) -> Vec<Self::Item> {
self.collect()
}
}
impl<T: Iterator> IteratorExt for T {}
fn main() {
let n = read!(usize);
let mut table = vec![false; n+1];
let primes = primes(n);
for i in 3..=n {
let x = primes
.iter()
.filter(|&&e| i-1 > e)
.map(|e| i - e)
.filter(|&e| table[e] == false)
.next();
if let Some(_) = x {
table[i] = true;
}
}
println!("{}", match table[n] {
true => "Win",
false => "Lose",
});
}
// n以下の素数一覧
fn primes(n: usize) -> Vec::<usize> {
if n < 2 {
return vec![];
}
let mut table = vec![true; n+1];
table[0] = false;
table[1] = false;
for i in 2..=(n as f64).sqrt() as usize {
if table[i] == false {
continue;
}
let mut j = i*i;
while j <= n {
table[j] = false;
j += i;
}
}
table
.iter()
.enumerate()
.filter(|(_, &flg)| flg)
.map(|(num, _)| num)
.collect()
}
sino