結果

問題 No.7 プライムナンバーゲーム
ユーザー mottodoramottodora
提出日時 2016-10-30 10:43:01
言語 Rust
(1.77.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 884 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 163,368 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:03:42
合計ジャッジ時間 1,501 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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");
    }
}
0