結果

問題 No.2766 Delicious Multiply Spice
ユーザー Mayimg
提出日時 2024-06-01 11:37:52
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 751 bytes
コンパイル時間 3,349 ms
コンパイル使用メモリ 267,008 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-21 17:53:49
合計ジャッジ時間 4,532 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 8
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize "O3,omit-frame-pointer,inline"
#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

signed main () {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  long long n;
  cin >> n;
  string ans;

  function<bool(long long)> dfs = [&](long long x) {
    if (x == 1) return true;
    cerr << "x = " << x << endl;
    x--;
    cerr << "x after decrement = " << x << endl;
    if (x % 2 == 0) {
      if (dfs(x / 2)) {
        ans += 'A';
        return true;
      }
    }
    if (x % 3 == 0) {
      if (dfs(x / 3)) {
        ans += 'B';
        return true;
      }
    }
    return false;
  };

  dfs(n);

  cout << ans << endl;
  return 0;  
}


0