-
Notifications
You must be signed in to change notification settings - Fork 0
/
12970.cpp
33 lines (26 loc) · 884 Bytes
/
12970.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<bits/stdc++.h>
using namespace std;
vector<char> answer;
int main() {
int N, K;
cin >> N >> K;
for (int num_A = 0; num_A <= N; num_A++) {
int num_B = N - num_A;
if (num_A * num_B > K) { // K보다 크면 a의 개수를 하나 적게 넣어준다.
for (int i = 0; i < num_A - 1; i++) answer.push_back('A');
for (int i = 0; i < num_B; i++) answer.push_back('B');
int left = K % num_B;
answer[answer.size() - left] = 'A'; // 하나 남은 A의 자리를 찾아 준다.
answer.push_back('B');
}
else if (num_A * num_B == K) { // K와 같다면 a, b의 개수를 순서대로 넣어준다.
for (int i = 0; i < num_A; i++) answer.push_back('A');
for (int i = 0; i < num_B; i++) answer.push_back('B');
}
else continue; // K보다 작으면 만들 수 없다.
break;
}
if (answer.size() == 0) cout << -1 << '\n';
else for (int i = 0; i < answer.size(); i++) cout << answer[i];
return 0;
}