#include <bits/stdc++.h>
#define rep(a,b,c) for(auto a = (b); a != (c); a++)
#define repD(a,b,c) for(auto a = (b); a != (c); a--)
#define repIn(a, b) for(auto& a : (b))
#define repIn2(a, b, c) for(auto& [a, b] : (c))
constexpr bool dbg = 1;
#define DEBUG if constexpr(dbg)
#define DC DEBUG std::cerr
#define eol std::endl
#define int long long
#define ld long double
#define pb push_back
using namespace std;
#define rg ranges
int chk(string s) {
auto n = (int)s.size();
int x = 0;
rep(i, 1, n + 1) {
bool g = 0;
rep(j, 0, n + 1 - i) {
if(g) break;
g = 1;
rep(k, 0, i) if(s[j + k] != s[j + i - k - 1]) {
g = 0;
break;
}
}
if(g) x = i;
}
return x;
}
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int t;
cin >> t;
if(t == 0) {
string s;
cin >> s;
cout << chk(s) << '\n';
return 0;
}
if(t < 0) {
int n, x;
cin >> n >> x;
rep(m, 0, 1 << n) {
string s;
rep(i, 0, n) s += ((m & (1 << i)) ? 'A' : 'P');
if(chk(s) == x) { cout << s << '\n'; return 0; }
}
cout << "NIE\n";
return 0;
}
while(t--) {
int n, x;
cin >> n >> x;
if(x >= 4) {
rep(i, 0, x) cout << 'A';
n -= x;
string s = "PPAPAA"; // Pen Pineapple Apple Pen AAAAAAAAAA
rep(i, 0, n) cout << s[i % 6];
cout << '\n';
}
else if(x == 3) {
if(n > 8) cout << "NIE\n";
else cout << string("AAAPAPPP").substr(0, n) << '\n';
}
else if(x == 2) {
if(n > 4) cout << "NIE\n";
else cout << string("AAPP").substr(0, n) << '\n';
}
else {
if(n > 2) cout << "NIE\n";
else cout << string("AP").substr(0, n) << '\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 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 | #include <bits/stdc++.h> #define rep(a,b,c) for(auto a = (b); a != (c); a++) #define repD(a,b,c) for(auto a = (b); a != (c); a--) #define repIn(a, b) for(auto& a : (b)) #define repIn2(a, b, c) for(auto& [a, b] : (c)) constexpr bool dbg = 1; #define DEBUG if constexpr(dbg) #define DC DEBUG std::cerr #define eol std::endl #define int long long #define ld long double #define pb push_back using namespace std; #define rg ranges int chk(string s) { auto n = (int)s.size(); int x = 0; rep(i, 1, n + 1) { bool g = 0; rep(j, 0, n + 1 - i) { if(g) break; g = 1; rep(k, 0, i) if(s[j + k] != s[j + i - k - 1]) { g = 0; break; } } if(g) x = i; } return x; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; if(t == 0) { string s; cin >> s; cout << chk(s) << '\n'; return 0; } if(t < 0) { int n, x; cin >> n >> x; rep(m, 0, 1 << n) { string s; rep(i, 0, n) s += ((m & (1 << i)) ? 'A' : 'P'); if(chk(s) == x) { cout << s << '\n'; return 0; } } cout << "NIE\n"; return 0; } while(t--) { int n, x; cin >> n >> x; if(x >= 4) { rep(i, 0, x) cout << 'A'; n -= x; string s = "PPAPAA"; // Pen Pineapple Apple Pen AAAAAAAAAA rep(i, 0, n) cout << s[i % 6]; cout << '\n'; } else if(x == 3) { if(n > 8) cout << "NIE\n"; else cout << string("AAAPAPPP").substr(0, n) << '\n'; } else if(x == 2) { if(n > 4) cout << "NIE\n"; else cout << string("AAPP").substr(0, n) << '\n'; } else { if(n > 2) cout << "NIE\n"; else cout << string("AP").substr(0, n) << '\n'; } } } |
English