結果

問題 No.715 集合と二人ゲーム
ユーザー koba-e964koba-e964
提出日時 2021-12-14 13:26:46
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,903 bytes
コンパイル時間 12,649 ms
コンパイル使用メモリ 399,864 KB
実行使用メモリ 7,660 KB
最終ジャッジ日時 2024-07-23 15:51:12
合計ジャッジ時間 15,691 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

// Tags: dawsons-chess, oeis, nim, octal-game
// ref: http://oeis.org/A002187
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut a = a;
    a.sort();
    let lim = 86;
    let mut dp = vec![0; lim];
    dp[1] = 1;
    for i in 2..lim {
        let mut seen = 1 << dp[i - 2];
        for j in 0..i - 2 {
            let x = dp[j] ^ dp[i - 3 - j];
            seen |= 1 << x;
        }
        let mut mex = 0;
        while (seen & 1 << mex) != 0 { mex += 1; }
        dp[i] = mex;
    }
    let gr = |mut a: usize| -> i32 {
        if a >= lim {
            a = (a - lim + 34) % 34 + lim - 34;
        }
        dp[a]
    };
    let mut last = -1;
    let mut c = 0;
    let mut ans = 0;
    for a in a {
        if last + 1 != a {
            ans ^= gr(c);
            c = 1;
        } else {
            c += 1;
        }
        last = a;
    }
    ans ^= gr(c);
    println!("{}", if ans == 0 { "Second" } else { "First" });
}
0