結果

問題 No.7 プライムナンバーゲーム
ユーザー phsplsphspls
提出日時 2020-06-02 22:39:43
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,796 ms / 5,000 ms
コード長 1,328 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 172,016 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:55:21
合計ジャッジ時間 12,062 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1,796 ms
6,948 KB
testcase_03 AC 43 ms
6,948 KB
testcase_04 AC 8 ms
6,944 KB
testcase_05 AC 9 ms
6,944 KB
testcase_06 AC 321 ms
6,944 KB
testcase_07 AC 187 ms
6,944 KB
testcase_08 AC 64 ms
6,948 KB
testcase_09 AC 574 ms
6,944 KB
testcase_10 AC 1 ms
6,948 KB
testcase_11 AC 190 ms
6,948 KB
testcase_12 AC 1,120 ms
6,944 KB
testcase_13 AC 1,224 ms
6,944 KB
testcase_14 AC 1,784 ms
6,948 KB
testcase_15 AC 1,657 ms
6,944 KB
testcase_16 AC 1,479 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn get_primes(n: usize) -> Vec<usize> {
    let mut flgs: Vec<bool> = vec![true; n+1];
    flgs[0] = false;
    flgs[1] = false;
    if n < 2 { return vec![]; }
    let lim = (n as f64).sqrt().ceil() as usize + 1;
    for i in 2..=lim {
        if !flgs[i] { continue; }
        for j in i..=n/i {
            flgs[i*j] = false;
        }
    }
    flgs.iter().enumerate().filter(|pair| *pair.1).map(|pair| pair.0).collect()
}

fn main() {
    //TODO
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();

    let primes: Vec<usize> = get_primes(n);
    let mut result: Vec<Option<usize>> = vec![None; n+1];
    result[2] = Some(0);
    if n > 2 {
        result[3] = Some(0);
    }
    for i in 4..=n {
        let mut temp: Vec<usize> = vec![];
        for p in primes.iter() {
            if *p > i - 2 { break; }
            if temp.contains(&p) { continue; }
            temp.push(result[i - p].unwrap());
        }
        temp.sort();
        let mut flg = false;
        for j in 0..temp.len() {
            if j == temp[j] { continue; }
            flg = true;
            result[i] = Some(j);
            break;
        }
        if !flg { result[i] = Some(temp.len()); }
    }
    println!("{}", if result[n] == Some(0) { "Lose" } else { "Win" });
}
0