結果

問題 No.2766 Delicious Multiply Spice
ユーザー well-definedwell-defined
提出日時 2024-09-15 13:47:38
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 841 bytes
コンパイル時間 14,056 ms
コンパイル使用メモリ 378,508 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-15 13:47:54
合計ジャッジ時間 15,153 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use proconio::input;

fn dfs (n: u128, ans: &mut Vec<char>) -> Result<(), ()> {
    //println!("now: {}, {:?}", n, ans);
    if n == 1 { return Ok(()); }
    if n == 0 { return Err(()); }
    if (n-1) % 2 != 0 && (n-1) % 3 != 0 { return Err(()); }
    if n % 2 == 0 {
        ans.push('B');
        dfs((n-1)/3, ans)?;
    }
    else {
        ans.push('A');
        match dfs((n-1)/2, ans) {
            Ok(()) => return Ok(()),
            Err(()) => {
                ans.pop();
                ans.push('B');
                dfs((n-1)/3, ans)?;
            }
        }
    }
    Err(())
}

fn main () {
    input! {
        mut n: u128,
    }
    let mut ans: Vec<char> = Vec::new();
    Some(dfs(n, &mut ans));
    let s = ans.iter()
        .rev()
        .map(|&c| c.to_string())
        .collect::<String>();
    println!("{}", s);
}
0