#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
template <class T>
using Ve = vector<T>;
#define ALL(v) (v).begin(), (v).end()
#define pii pair<ll, ll>
#define rep(i, a, b) for(ll i = (a); i <= (b); ++i)
#define per(i, a, b) for(ll i = (a); i >= (b); --i)
#define pb push_back
bool Mbe;
ll read() {
ll x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
void write(ll x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
}
const ll N = 1e6 + 9;
ll n, K, a[N];
void solve() {
n = read(), K = read();
if(n <= 10) {
rep(S, 0, (1 << n) - 1) {
rep(i, 0, n - 1) a[i] = (S >> i) & 1;
ll mx = 0;
rep(l, 0, n - 1) {
rep(r, l, n - 1) {
bool fl = 1;
rep(k, l, r) {
ll par = r - (k - l);
if(a[k] != a[par]) {
fl = 0;
break;
}
}
if(fl) mx = max(mx, r - l + 1);
}
}
if(mx == K) {
rep(i, 0, n - 1) {
if(a[i]) putchar('A');
else putchar('P');
}
putchar('\n');
return ;
}
}
puts("NIE");
}
else {
if(K <= 3) puts("NIE");
else {
string s = "";
rep(i, 1, K) s.pb('P');
rep(i, 0, n - K - 1) {
ll t = i % 6;
if(t == 0 || t == 2 || t == 3) s.pb('A');
else s.pb('P');
}
cout << s << "\n";
}
}
}
bool Med;
int main() {
cerr << fabs(&Med - &Mbe) / 1048576.0 << "MB\n";
ll T = read();
while(T--) solve();
cerr << "\n" << clock() * 1.0 / CLOCKS_PER_SEC * 1000 << "ms\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 | #include <bits/stdc++.h> using ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; template <class T> using Ve = vector<T>; #define ALL(v) (v).begin(), (v).end() #define pii pair<ll, ll> #define rep(i, a, b) for(ll i = (a); i <= (b); ++i) #define per(i, a, b) for(ll i = (a); i >= (b); --i) #define pb push_back bool Mbe; ll read() { ll x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();} while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * f; } void write(ll x) { if(x < 0) putchar('-'), x = -x; if(x > 9) write(x / 10); putchar(x % 10 + '0'); } const ll N = 1e6 + 9; ll n, K, a[N]; void solve() { n = read(), K = read(); if(n <= 10) { rep(S, 0, (1 << n) - 1) { rep(i, 0, n - 1) a[i] = (S >> i) & 1; ll mx = 0; rep(l, 0, n - 1) { rep(r, l, n - 1) { bool fl = 1; rep(k, l, r) { ll par = r - (k - l); if(a[k] != a[par]) { fl = 0; break; } } if(fl) mx = max(mx, r - l + 1); } } if(mx == K) { rep(i, 0, n - 1) { if(a[i]) putchar('A'); else putchar('P'); } putchar('\n'); return ; } } puts("NIE"); } else { if(K <= 3) puts("NIE"); else { string s = ""; rep(i, 1, K) s.pb('P'); rep(i, 0, n - K - 1) { ll t = i % 6; if(t == 0 || t == 2 || t == 3) s.pb('A'); else s.pb('P'); } cout << s << "\n"; } } } bool Med; int main() { cerr << fabs(&Med - &Mbe) / 1048576.0 << "MB\n"; ll T = read(); while(T--) solve(); cerr << "\n" << clock() * 1.0 / CLOCKS_PER_SEC * 1000 << "ms\n"; return 0; } |
English