結果

問題 No.2766 Delicious Multiply Spice
コンテスト
ユーザー forest3
提出日時 2024-07-12 12:12:47
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 569 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,524 ms
コンパイル使用メモリ 182,116 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-30 10:14:04
合計ジャッジ時間 2,641 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 8
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
	ll N;
	cin >> N;
	string ans = "";
	function<int(ll)> dfs = [&](ll x)
	{
		if(x == 1) return 0;
		ll nx = (x - 1) / 2;
		int m = (x - 1) % 2;
		if(m == 0 && nx > 0) {
			int ret = dfs(nx);
			if(ret == 0) {
				ans += "A";
				return 0;
			}
		}
		nx = (x - 1) / 3;
		m = (x - 1) % 3;
		if(m == 0 && nx > 0) {
			int ret = dfs(nx);
			if(ret == 0) {
				ans += "B";
				return 0;
			}
		}
		return -1;
	};
	dfs(N);
	cout << ans << endl;
}

0