// clang-format off
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define FOR(i,l,r) for(auto i=(l);i<=(r);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
// clang-format on
const array<string, 7> solutions = {"PA", "PPAA", "PPPAPAAA", "AAPAPP"};
bool
solve()
{
int N, K;
cin >> N >> K;
if (K > N) return false;
if (K >= 4) {
REP (i, K) cout << "P";
N -= K;
K = 4;
for (; N >= ssize(solutions[K - 1]); N -= ssize(solutions[K - 1]))
cout << solutions[K - 1].c_str();
}
const auto &sol = solutions[K - 1];
if (N > ssize(sol)) return false;
cout << sol.substr(0, N).c_str() << "\n";
return true;
}
int
main()
{
cin.tie(0)->sync_with_stdio(0);
int T;
cin >> T;
while (T--) {
if (!solve()) 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 | // clang-format off #include<bits/stdc++.h> using namespace std; using LL=long long; #define FOR(i,l,r) for(auto i=(l);i<=(r);++i) #define REP(i,n) FOR(i,0,(n)-1) #define ssize(x) int(x.size()) // clang-format on const array<string, 7> solutions = {"PA", "PPAA", "PPPAPAAA", "AAPAPP"}; bool solve() { int N, K; cin >> N >> K; if (K > N) return false; if (K >= 4) { REP (i, K) cout << "P"; N -= K; K = 4; for (; N >= ssize(solutions[K - 1]); N -= ssize(solutions[K - 1])) cout << solutions[K - 1].c_str(); } const auto &sol = solutions[K - 1]; if (N > ssize(sol)) return false; cout << sol.substr(0, N).c_str() << "\n"; return true; } int main() { cin.tie(0)->sync_with_stdio(0); int T; cin >> T; while (T--) { if (!solve()) cout << "NIE\n"; } return 0; } |
English