結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
mottodora
|
| 提出日時 | 2016-10-30 10:43:01 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 5,000 ms |
| コード長 | 884 bytes |
| コンパイル時間 | 13,850 ms |
| コンパイル使用メモリ | 378,516 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-01 15:49:42 |
| 合計ジャッジ時間 | 13,022 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
fn getline() -> String{
let mut ret = String::new();
std::io::stdin().read_line(&mut ret).ok();
return ret;
}
fn eratosthenes(n: i32) -> Vec<i32> {
let mut v: Vec<i32> = (2..n+1).collect();
let mut i:i32 = 0;
while i < v.len() as i32 {
let a = v[i as usize];
v.retain(|&x| x< a+1 || x % a !=0);
i+=1;
}
v
}
fn main() {
let n: i32 = getline().trim().parse().unwrap();
let primes = eratosthenes(n);
let mut dp = [false; 10001];
let l = primes.len() as i32;
for i in 4..(n+1) {
let mut j = 0;
while primes[j as usize] <= i-2{
dp[i as usize] |= !dp[(i - primes[j as usize]) as usize];
j += 1;
if j >= l {
break;
}
}
}
if dp[n as usize] {
println!("Win");
}
else {
println!("Lose");
}
}
mottodora