#include <bits/stdc++.h>
using namespace std;
// do rozwiazania uzylem informacji z posta https://math.stackexchange.com/questions/1321778/what-is-the-minimum-length-of-maximal-palindrome-of-a-binary-word-of-length-n
// oraz artykulu https://cs.uwaterloo.ca/~shallit/Papers/ras-reversed.pdf
string solve(int l, int k) {
string ans = "";
for (int i = 0; i < k; i++) {
ans += 'A';
}
string smegma = "PPAPAA";
for (int i = k; i < l; i++) {
ans += smegma[(i - k) % 6];
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
if (b >= 4) {
string ans = solve(a, b);
cout << ans << endl;
} else {
if (a == 1 && b == 1) {
cout << "A\n";
continue;
}
if (a == 2 && b == 1) {
cout << "AP\n";
continue;
}
if (a == 2 && b == 2) {
cout << "AA\n";
continue;
}
if (a == 3 && b == 2) {
cout << "AAP\n";
continue;
}
if (a == 3 && b == 3) {
cout << "AAA\n";
continue;
}
if (a == 4 && b == 2) {
cout << "AAPP\n";
continue;
}
if (a == 4 && b == 3) {
cout << "AAAP\n";
continue;
}
if (a == 5 && b == 3) {
cout << "AAAPA\n";
continue;
}
if (a == 6 && b == 3) {
cout << "AAAPAP\n";
continue;
}
if (a == 7 && b == 3) {
cout << "AAAPAPP\n";
continue;
}
if (a == 8 && b == 3) {
cout << "AAAPAPPP\n";
continue;
}
cout << "NIE\n";
}
}
return 0;
}
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #include <bits/stdc++.h> using namespace std; // do rozwiazania uzylem informacji z posta https://math.stackexchange.com/questions/1321778/what-is-the-minimum-length-of-maximal-palindrome-of-a-binary-word-of-length-n // oraz artykulu https://cs.uwaterloo.ca/~shallit/Papers/ras-reversed.pdf string solve(int l, int k) { string ans = ""; for (int i = 0; i < k; i++) { ans += 'A'; } string smegma = "PPAPAA"; for (int i = k; i < l; i++) { ans += smegma[(i - k) % 6]; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int t; cin >> t; while (t--) { int a, b; cin >> a >> b; if (b >= 4) { string ans = solve(a, b); cout << ans << endl; } else { if (a == 1 && b == 1) { cout << "A\n"; continue; } if (a == 2 && b == 1) { cout << "AP\n"; continue; } if (a == 2 && b == 2) { cout << "AA\n"; continue; } if (a == 3 && b == 2) { cout << "AAP\n"; continue; } if (a == 3 && b == 3) { cout << "AAA\n"; continue; } if (a == 4 && b == 2) { cout << "AAPP\n"; continue; } if (a == 4 && b == 3) { cout << "AAAP\n"; continue; } if (a == 5 && b == 3) { cout << "AAAPA\n"; continue; } if (a == 6 && b == 3) { cout << "AAAPAP\n"; continue; } if (a == 7 && b == 3) { cout << "AAAPAPP\n"; continue; } if (a == 8 && b == 3) { cout << "AAAPAPPP\n"; continue; } cout << "NIE\n"; } } return 0; } |
English