結果

問題 No.715 集合と二人ゲーム
ユーザー fukafukatanifukafukatani
提出日時 2019-02-09 11:23:23
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,586 bytes
コンパイル時間 5,030 ms
コンパイル使用メモリ 169,556 KB
実行使用メモリ 11,468 KB
最終ジャッジ日時 2023-09-14 11:04:50
合計ジャッジ時間 16,436 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 TLE -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn grundy(m: usize, mem: &mut Vec<i32>) -> i32 {
    if mem[m] != -1 {
        return mem[m];
    }
    let mut s = HashSet::new();
    s.insert(mem[m - 1]);
    if m > 1 {
        s.insert(mem[m - 2]);
    }
    if m > 2 {
        for i in 0..m - 3 + 1 {
            s.insert(mem[i] ^ mem[m - i - 3]);
        }
    }
    let mut res = 0;
    while s.contains(&res) {
        res += 1;
    }
    mem[m] = res;
    res - 1
}

fn main() {
    let n: usize = read();
    let mut a: Vec<u64> = read_vec();
    a.sort();
    let mut mountains = Vec::new();
    mountains.push(1);
    for i in 1..n {
        if a[i] == a[i - 1] + 1 {
            let last_elem = mountains.len() - 1;
            mountains[last_elem] += 1;
        } else {
            mountains.push(1);
        }
    }
    let max_elem = *mountains.iter().max().unwrap();
    let mut mem = vec![-1; max_elem + 1];
    mem[0] = 0;
    for m in 0..max_elem + 1 {
        grundy(m, &mut mem);
    }
    println!("{:?}", mountains);
    println!("{:?}", mem);
    let result = mountains.iter().fold(0, |s, &x| s ^ mem[x]);
    if result == 0 {
        println!("Second");
    } else {
        println!("First");
    }
}
0