結果

問題 No.153 石の山
ユーザー nayo0513
提出日時 2025-04-26 21:17:32
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,124 bytes
コンパイル時間 13,426 ms
コンパイル使用メモリ 398,308 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-26 21:17:47
合計ジャッジ時間 13,646 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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,
    }
    let ans = f(n, &mut vec![None; 101]);
    println!("{}", if ans != 0 { "A" } else { "B" });
}
fn f(x: usize, memo: &mut [Option<usize>]) -> usize {
    if let Some(v) = memo[x] {
        return v;
    }
    let mut set = HashSet::new();
    if x % 2 == 0 && x >= 2 {
        set.insert(f(x / 2, memo) ^ f(x / 2, memo));
    }
    if x % 2 == 1 && x >= 3 {
        set.insert(f(x / 2, memo) ^ f(x / 2 + 1, memo));
    }
    if x % 3 == 0 && x >= 3 {
        set.insert(f(x / 3, memo) ^ f(x / 3, memo) ^ f(x / 3, memo));
    }
    if x % 3 == 1 && x >= 4 {
        set.insert(f(x / 3, memo) ^ f(x / 3, memo) ^ f(x / 3 + 1, memo));
    }
    if x % 3 == 2 && x >= 5 {
        set.insert(f(x / 3, memo) ^ f(x / 3 + 1, memo) ^ f(x / 3 + 1, memo));
    }
    let mut res = 0;
    while set.contains(&res) {
        res += 1;
    }
    memo[x] = Some(res);
    res
}
0