結果

問題 No.361 門松ゲーム2
ユーザー nayo0513
提出日時 2025-04-26 21:58:19
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,057 bytes
コンパイル時間 12,720 ms
コンパイル使用メモリ 400,804 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-26 21:58:34
合計ジャッジ時間 14,425 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashSet;

use proconio::input;

fn main() {
    // let mut stdin = LineSource::new(BufReader::new(io::stdin()));
    // macro_rules! input(($($tt:tt)*) => (proconio::input!(from &mut stdin, $($tt)*)));
    input! {
        n:usize,
        d:usize
    }
    println!(
        "{}",
        if f(n, d, &mut vec![None; n + 1]) != 0 {
            "kado"
        } else {
            "matsu"
        }
    );
}
fn f(x: usize, d: usize, memo: &mut [Option<usize>]) -> usize {
    if let Some(v) = memo[x] {
        return v;
    }
    let mut set = HashSet::new();
    for i in 1..=x {
        for j in i + 1..=x {
            if i + j >= x {
                break;
            }
            let k = x - i - j;
            if k >= i {
                continue;
            }
            if j - k > d {
                continue;
            }
            set.insert(f(i, d, memo) ^ f(j, d, memo) ^ f(k, d, memo));
        }
    }
    let mut res = 0;
    while set.contains(&res) {
        res += 1;
    }
    memo[x] = Some(res);
    res
}
0