結果

問題 No.715 集合と二人ゲーム
ユーザー fukafukatanifukafukatani
提出日時 2019-02-09 11:28:45
言語 Rust
(1.72.1)
結果
TLE  
実行時間 -
コード長 1,611 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 157,420 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 11:06:41
合計ジャッジ時間 9,865 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 10 ms
4,376 KB
testcase_06 AC 12 ms
4,380 KB
testcase_07 AC 17 ms
4,376 KB
testcase_08 AC 22 ms
4,376 KB
testcase_09 AC 27 ms
4,376 KB
testcase_10 AC 29 ms
4,380 KB
testcase_11 AC 36 ms
4,376 KB
testcase_12 AC 46 ms
4,380 KB
testcase_13 AC 52 ms
4,376 KB
testcase_14 AC 57 ms
4,376 KB
testcase_15 AC 70 ms
4,380 KB
testcase_16 AC 72 ms
4,380 KB
testcase_17 AC 63 ms
4,376 KB
testcase_18 AC 92 ms
4,376 KB
testcase_19 AC 104 ms
4,380 KB
testcase_20 AC 95 ms
4,376 KB
testcase_21 AC 120 ms
4,376 KB
testcase_22 AC 137 ms
4,376 KB
testcase_23 AC 146 ms
4,380 KB
testcase_24 AC 167 ms
4,376 KB
testcase_25 AC 164 ms
4,376 KB
testcase_26 AC 159 ms
4,376 KB
testcase_27 AC 184 ms
4,376 KB
testcase_28 AC 223 ms
4,376 KB
testcase_29 AC 233 ms
4,376 KB
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 = BTreeSet::new();

    if m > 1 {
        s.insert(mem[m - 2]);
    } else {
        s.insert(mem[m - 1]);
    }
    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;
    // println!("{:?}", mountains);
    // println!("{:?}", mem);
    for m in 0..max_elem + 1 {
        grundy(m, &mut mem);
    }
    let result = mountains.iter().fold(0, |s, &x| s ^ mem[x]);
    if result == 0 {
        println!("Second");
    } else {
        println!("First");
    }
}
0