結果
問題 | No.2766 Delicious Multiply Spice |
ユーザー |
|
提出日時 | 2024-05-31 21:48:45 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,109 bytes |
コンパイル時間 | 14,923 ms |
コンパイル使用メモリ | 400,128 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-20 23:07:45 |
合計ジャッジ時間 | 15,920 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 8 |
other | AC * 31 |
ソースコード
use proconio::input; // #[proconio::fastout] fn main() { input! { n: usize, } let mut result = Vec::new(); // let mut x = n; // loop { // println!("{}", x); // if x == 1 { // break; // } // x -= 1; // println!("-1 {}", x); // if x % 2 == 0 { // result.push('A'); // x /= 2; // println!("/2 {}", x); // } else if x % 3 == 0 { // result.push('B'); // x /= 3; // println!("/3{}", x); // } // } rec(n, &mut result); let text: String = result.into_iter().collect(); println!("{}", text); } fn rec(n: usize, result: &mut Vec<char>) -> bool { if n == 1 { return true; } if n == 2 { return false; } let x = n - 1; if x % 2 == 0 { if rec(x / 2, result) { result.push('A'); return true; } } if x % 3 == 0 { if rec(x / 3, result) { result.push('B'); return true; } } false }