結果

問題 No.7 プライムナンバーゲーム
ユーザー TiramisterTiramister
提出日時 2018-09-03 19:26:28
言語 Rust
(1.77.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,384 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 164,732 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:31:43
合計ジャッジ時間 1,417 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,820 KB
testcase_01 AC 1 ms
6,948 KB
testcase_02 AC 11 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 2 ms
6,948 KB
testcase_09 AC 5 ms
6,948 KB
testcase_10 AC 1 ms
6,948 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 7 ms
6,944 KB
testcase_13 AC 8 ms
6,944 KB
testcase_14 AC 11 ms
6,944 KB
testcase_15 AC 10 ms
6,948 KB
testcase_16 AC 9 ms
6,944 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 make_primes(n: usize) -> Vec<usize> {
    let mut primes: Vec<usize> = Vec::new();

    let mut is_prime: Vec<bool> = vec![true; n+1];
    is_prime[1] = false;

    for i in 2..n+1 {
        if !is_prime[i] {continue};
        primes.push(i);

        for j in 2..n+1 {
            if i * j > n {break;}
            is_prime[i * j] = false;
        }
    }
    primes
}


fn main() {
    let n: usize = cast(&get_line());
    let primes = make_primes(n);

    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