結果

問題 No.361 門松ゲーム2
ユーザー o_loAol_oo_loAol_o
提出日時 2021-11-02 19:37:38
言語 Rust
(1.77.0)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 1,562 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 175,168 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 05:47:28
合計ジャッジ時間 2,463 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 0 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 0 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 86 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 25 ms
6,944 KB
testcase_17 AC 8 ms
6,940 KB
testcase_18 AC 5 ms
6,944 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 28 ms
6,940 KB
testcase_22 AC 245 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 8 ms
6,944 KB
testcase_27 AC 12 ms
6,944 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 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>
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