結果
| 問題 | No.3135 AAABC |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-24 11:51:43 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| + 414µs | |
| コード長 | 1,163 bytes |
| 記録 | |
| コンパイル時間 | 2,078 ms |
| コンパイル使用メモリ | 335,456 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-07-14 11:16:17 |
| 合計ジャッジ時間 | 4,014 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
}
}