結果
問題 |
No.361 門松ゲーム2
|
ユーザー |
![]() |
提出日時 | 2021-11-02 19:30:22 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,525 bytes |
コンパイル時間 | 15,706 ms |
コンパイル使用メモリ | 378,624 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 00:39:47 |
合計ジャッジ時間 | 17,052 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 WA * 13 |
ソースコード
// 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 bit = 1; 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; } if grundy(i, d, dp) == 0 && grundy(j, d, dp) == 0 && grundy(k, d, dp) == 0 { bit *= 0 } } } let rt = bit ^ 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> where T: 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() }