結果
| 問題 | No.3135 AAABC |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-24 11:51:43 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,163 bytes |
| 記録 | |
| コンパイル時間 | 3,485 ms |
| コンパイル使用メモリ | 281,136 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-08-24 11:51:48 |
| 合計ジャッジ時間 | 4,512 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); ++i)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define fore(i, a) for(auto &i:a)
using ll = long long;
int main() {
int n;cin >> n;
int s;cin >> s;
vector<int> three(n+2), two(n+2);
three[0] = 1;two[0] = 1;
rep(i, n+1){
three[i+1] = three[i]*3;
two[i+1] = two[i]*2;
}
int rem = s;
bool eA = false,eB = false, eC = false;
string ans(n, '*');
vector<char> clist ={'A','B','C'};
rep(i, n){
fore(c, clist){
int t = (eA || c == 'A')+(eB || c == 'B')+(eC || c == 'C');
int kouho;
if(t == 1){
kouho = three[n-1-i]-two[n-i]+1;
}
else if(t == 2){
kouho = three[n-1-i]-two[n-1-i];
}
else{
kouho = three[n-1-i];
}
if(rem > kouho){
rem-=kouho;
if(c == 'C'){
cout << -1 << endl;
return 0;
}
}
else{
ans[i] = c;
if(c == 'A')eA = true;
if(c == 'B')eB = true;
if(c == 'C')eC = true;
break;
}
}
}
if(rem == 1){
cout << ans << endl;
}
else{
cout << -1 << endl;
}
}