#include <bits/stdc++.h>
using namespace std;
string brut(int n, int k) {
for (int m = 0; m < (1 << n); ++m) {
int x = m;
string s;
for (int i = 0; i < n; ++i) {
s += "PA"[x & 1];
x /= 2;
}
int maxx = 1;
for (int i = 0; i < n; ++i) {
for (int d = 1; d <= n - i; ++d) {
string t = s.substr(i, d);
if (t == string{t.rbegin(), t.rend()}) {
maxx = max(maxx, d);
}
}
}
if (maxx == k) {
return s;
}
}
return "NIE";
}
void test_case() {
int n, k;
cin >> n >> k;
if (n <= 8) {
cout << brut(n, k) << '\n';
return;
}
if (k < 4) {
cout << "NIE\n";
return;
}
char c = 'A';
cout << string(k - 2, 'A');
for (int i = 0; i < n - (k - 2); ++i) {
cout << (c = "AAPAPP"[i % 6]);
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
test_case();
}
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 | #include <bits/stdc++.h> using namespace std; string brut(int n, int k) { for (int m = 0; m < (1 << n); ++m) { int x = m; string s; for (int i = 0; i < n; ++i) { s += "PA"[x & 1]; x /= 2; } int maxx = 1; for (int i = 0; i < n; ++i) { for (int d = 1; d <= n - i; ++d) { string t = s.substr(i, d); if (t == string{t.rbegin(), t.rend()}) { maxx = max(maxx, d); } } } if (maxx == k) { return s; } } return "NIE"; } void test_case() { int n, k; cin >> n >> k; if (n <= 8) { cout << brut(n, k) << '\n'; return; } if (k < 4) { cout << "NIE\n"; return; } char c = 'A'; cout << string(k - 2, 'A'); for (int i = 0; i < n - (k - 2); ++i) { cout << (c = "AAPAPP"[i % 6]); } cout << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { test_case(); } return 0; } |
English