結果

問題 No.361 門松ゲーム2
ユーザー o_loAol_oo_loAol_o
提出日時 2021-11-02 19:30:22
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,525 bytes
コンパイル時間 1,983 ms
コンパイル使用メモリ 167,168 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 05:38:36
合計ジャッジ時間 2,392 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 28 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 9 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 WA -
testcase_22 AC 100 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 1 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 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()
}
0