#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int najPal(const string &s, int l, int p)
{
int wyn=0;
while (0<=l && p<s.size() && s[l]==s[p])
{
if (l==p)
++wyn;
else
wyn+=2;
--l;
++p;
}
return wyn;
}
int najPal(const string &s)
{
int wyn=0;
for (int i=0; i<s.size(); ++i)
wyn=max(wyn, max(najPal(s, i, i), najPal(s, i, i+1)));
return wyn;
}
string s;
int n, k;
bool byl;
int spr()
{
if (byl)
return -1;
if (s.size()<n)
{
s.push_back('A');
int a=spr();
s.pop_back();
s.push_back('P');
int b=spr();
s.pop_back();
return min(a, b);
}
int wyn=najPal(s);
if (wyn==k)
{
byl=true;
cout<<s<<'\n';
}
return wyn;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string p(1000000, 'A');
string q("PPAPAA");
while (q.size()<1000000)
q+=q;
int t;
cin>>t;
for (int tt=0; tt<t; ++tt)
{
cin>>n>>k;
if (n<9)
{
byl=false;
s.clear();
spr();
if (!byl)
cout<<"NIE\n";
}
else
{
if (k<4)
cout<<"NIE\n";
else
{
if (k==4)
cout<<q.substr(0, n);
else
cout<<p.substr(0, k)<<q.substr(0, n-k);
cout<<'\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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | #include <iostream> #include <string> #include <algorithm> using namespace std; int najPal(const string &s, int l, int p) { int wyn=0; while (0<=l && p<s.size() && s[l]==s[p]) { if (l==p) ++wyn; else wyn+=2; --l; ++p; } return wyn; } int najPal(const string &s) { int wyn=0; for (int i=0; i<s.size(); ++i) wyn=max(wyn, max(najPal(s, i, i), najPal(s, i, i+1))); return wyn; } string s; int n, k; bool byl; int spr() { if (byl) return -1; if (s.size()<n) { s.push_back('A'); int a=spr(); s.pop_back(); s.push_back('P'); int b=spr(); s.pop_back(); return min(a, b); } int wyn=najPal(s); if (wyn==k) { byl=true; cout<<s<<'\n'; } return wyn; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string p(1000000, 'A'); string q("PPAPAA"); while (q.size()<1000000) q+=q; int t; cin>>t; for (int tt=0; tt<t; ++tt) { cin>>n>>k; if (n<9) { byl=false; s.clear(); spr(); if (!byl) cout<<"NIE\n"; } else { if (k<4) cout<<"NIE\n"; else { if (k==4) cout<<q.substr(0, n); else cout<<p.substr(0, k)<<q.substr(0, n-k); cout<<'\n'; } } } return 0; } |
English