結果
問題 | No.361 門松ゲーム2 |
ユーザー |
![]() |
提出日時 | 2021-11-02 19:37:38 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 282 ms / 2,000 ms |
コード長 | 1,562 bytes |
コンパイル時間 | 13,549 ms |
コンパイル使用メモリ | 386,008 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-12 00:50:01 |
合計ジャッジ時間 | 14,544 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
// No.361 (https://yukicoder.me/problems/no/361)// 門松ゲーム2#![allow(unreachable_code)]fn main() {let (l, d) = input();let mut dp = std::collections::HashMap::new();for i in 1..6 {dp.insert(i, 0);}if grundy(l, d, &mut dp) == 0 {println!("matsu")} else {println!("kado")}// println!("{:#?}", dp)}fn grundy(l: usize, d: usize, dp: &mut std::collections::HashMap<usize, usize>) -> usize {if let Some(&v) = dp.get(&l) {v} else {let mut set = std::collections::HashSet::new();for i in 1..l {for j in i + 1..l {if i + j >= l {break;}let k = l - i - j;if k <= j {break;}if k - i > d {continue;}set.insert(grundy(i, d, dp) ^ grundy(j, d, dp) ^ grundy(k, d, dp));}}let mut rt = 0;while set.contains(&rt) {rt += 1}dp.insert(l, rt);rt}}#[inline(always)]fn input() -> (usize, usize) {let e = read_line::<usize>();(e[0], e[1])}#[inline(always)]fn read_line<T>() -> Vec<T>whereT: std::str::FromStr,<T as std::str::FromStr>::Err: std::fmt::Debug,{let mut s = String::new();std::io::stdin().read_line(&mut s).unwrap();s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()}