#include <bits/stdc++.h>
using namespace std;
string solve(int n, int k) {
assert(k <= n);
if (k == 1) {
if (n == 1) return "A";
if (n == 2) return "AP";
return "";
}
if (k == 2) {
const string ANS = "AAPP";
if (n <= (int)ANS.size()) return ANS.substr(0, n);
return "";
}
if (k == 3) {
const string ANS = "AAAPAPPP";
if (n <= (int)ANS.size()) return ANS.substr(0, n);
return "";
}
string res(n, ' ');
for (int i = 0; i < n; i++) {
int z = i%(2*(k-1));
int u = (z < k-1)^(z == 0)^(z == 2*k-3);
res[i] = u ? 'A' : 'P';
}
return res;
}
int main () {
ios_base::sync_with_stdio(0); cin.tie(0);
int T;
cin >> T;
while (T--) {
int n, k;
cin >> n >> k;
string res = solve(n, k);
if (res.empty()) cout << "NIE\n";
else cout << res << '\n';
}
}
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 | #include <bits/stdc++.h> using namespace std; string solve(int n, int k) { assert(k <= n); if (k == 1) { if (n == 1) return "A"; if (n == 2) return "AP"; return ""; } if (k == 2) { const string ANS = "AAPP"; if (n <= (int)ANS.size()) return ANS.substr(0, n); return ""; } if (k == 3) { const string ANS = "AAAPAPPP"; if (n <= (int)ANS.size()) return ANS.substr(0, n); return ""; } string res(n, ' '); for (int i = 0; i < n; i++) { int z = i%(2*(k-1)); int u = (z < k-1)^(z == 0)^(z == 2*k-3); res[i] = u ? 'A' : 'P'; } return res; } int main () { ios_base::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { int n, k; cin >> n >> k; string res = solve(n, k); if (res.empty()) cout << "NIE\n"; else cout << res << '\n'; } } |
English