結果
| 問題 | No.715 集合と二人ゲーム |
| コンテスト | |
| ユーザー |
tubo28
|
| 提出日時 | 2017-10-04 13:24:24 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,684 bytes |
| 記録 | |
| コンパイル時間 | 13,491 ms |
| コンパイル使用メモリ | 379,632 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 09:29:01 |
| 合計ジャッジ時間 | 16,770 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 6 RE * 54 |
ソースコード
use std::io::*;
use std::str::*;
fn readw<T: FromStr, R: Read>(s: &mut R) -> Option<T> {
let s = s.bytes().map(|c| c.unwrap() as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect::<String>();
if s.is_empty() {
None
} else {
s.parse::<T>().ok()
}
}
const MAX_M: usize = 30;
fn read<T: FromStr, R: Read>(s: &mut R) -> T {
readw(s).unwrap()
}
fn grundy(n: u32, dp: &mut Vec<Option<u32>>) -> u32 {
if let Some(res) = dp[n as usize] {
res
} else {
let res = if n == 1 || n == 0 {
n
} else {
let mut s = [false; MAX_M];
s[grundy(n - 2, dp) as usize] = true;
for i in 0..n-2 {
s[(grundy(i, dp) ^ grundy(n - 3 - i, dp)) as usize] = true;
}
(0..MAX_M).find(|&x| !s[x]).unwrap() as u32
};
dp[n as usize] = Some(res);
// println!("{} {}", n, res);
res
}
}
fn main() {
let s = stdin();
let s = s.lock();
let s = &mut BufReader::new(s);
for _ in 0..1 {
let n: usize = read(s);
println!("{}", n);
let mut a: Vec<u32> = (0..n).map(|_| read(s)).collect();
a.sort();
let mut g = 0;
let mut dp = vec![None; 32];
let mut i = 0;
while i < n {
let mut j = i;
while j + 1 < n && a[j + 1] == a[j] + 1 {
j += 1;
}
// [i,j]
let k = j - i + 1;
g ^= grundy(k as u32, &mut dp);
i = j + 1;
}
println!("{}", if g == 0 { "Second" } else { "First" });
}
}
tubo28