結果

問題 No.3135 AAABC
ユーザー tobbie
提出日時 2025-05-29 14:02:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 2,452 ms
コンパイル使用メモリ 193,992 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-05-29 14:02:09
合計ジャッジ時間 3,713 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int main() {
  int n;
  cin >> n;
  int s;
  cin >> s;
  vector<int> a(3, 0);
  a[0] = n;
  vector<int> t(n, 0);
  int in = 0;
  int on = 0;
  int p = 1;
  rep(i, n) {
    on += p * 2;
    p *= 3;
  }
  rep(i, s) {
    bool zero = true;
    int c = 0;
    while (zero) {
      in++;
      c = 1;
      rep(j, n) {
	a[t[j]]--;
	t[j] += c;
	c = t[j] / 3;
	t[j] %= 3;
	a[t[j]]++;
      }
      zero = false;
      rep(j, 3)
	if (a[j] == 0) zero = true;
    }
  }
  if (in > on) {
    cout << -1 << endl;
  } else {
    rep(i, n)
      cout << (char)('A' + t[(n-1) - i]);
    cout << endl;
  }
  return 0;
}
0