結果

問題 No.7 プライムナンバーゲーム
ユーザー TiramisterTiramister
提出日時 2018-09-03 19:10:16
言語 Rust
(1.77.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,404 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 169,740 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:31:36
合計ジャッジ時間 1,571 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,560 KB
testcase_01 AC 1 ms
6,696 KB
testcase_02 AC 18 ms
6,692 KB
testcase_03 AC 3 ms
6,692 KB
testcase_04 AC 2 ms
6,688 KB
testcase_05 AC 2 ms
6,688 KB
testcase_06 AC 8 ms
6,692 KB
testcase_07 AC 7 ms
6,688 KB
testcase_08 AC 4 ms
6,692 KB
testcase_09 AC 10 ms
6,692 KB
testcase_10 AC 1 ms
6,692 KB
testcase_11 AC 7 ms
6,688 KB
testcase_12 AC 15 ms
6,692 KB
testcase_13 AC 15 ms
6,692 KB
testcase_14 AC 18 ms
6,692 KB
testcase_15 AC 18 ms
6,692 KB
testcase_16 AC 16 ms
6,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn get_line() -> String {
    let stdin = stdin();
    let mut line = String::new();
    stdin.lock().read_line(&mut line).expect("io error.");
    line.trim().to_string()
}

#[allow(dead_code)]
fn cast<T: FromStr>(s: &str) -> T {
    s.parse().ok().expect("parse error.")
}

#[allow(dead_code)]
fn get_vec<T: FromStr>() -> Vec<T> {
    (&get_line()).split(' ').map(cast::<T>).collect()
}


/* ---------- ここまでテンプレ ---------- */


fn main() {
    // まずはエラトステネスの篩
    let mut is_prime: Vec<bool> = vec![true; 10001];
    is_prime[1] = false;
    for i in 2..101 {
        if !is_prime[i] {continue};
        for j in 2..10000 {
            if i * j > 10000 {break;}
            is_prime[i * j] = false;
        }
    }

    // filterで素数配列を生成
    let primes: Vec<usize> =
        (1..10001)
            .filter(|x| is_prime[*x])
            .collect();


    // ここからが本編
    let n: usize = cast(&get_line());
    let mut dp: Vec<bool> = vec![true; n + 1];
    // 自分の番がmで回ってきたときに勝てるならtrue

    for m in 2..n+1{
        let mut ret = false;
        for p in &primes {
            if m > *p {
                ret |= !dp[m - *p];
            }
        }
        dp[m] = ret;
    }

    println!("{}",
        if dp[n] {"Win"} else {"Lose"});
}
0