#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define DEBUG
#ifdef DEBUG
template<typename T1,typename T2>auto& operator<<(ostream&o,pair<T1,T2>a){return o<<"("<<a.first<<", "<<a.second<<")";}
template<typename T,size_t...I>void pt(ostream&o,T t,index_sequence<I...>){o<<"(";(...,(o<<(I?", ":"")<< get<I>(t)));o<<")";}
template<typename...A>auto& operator<<(ostream&o,tuple<A...>t){pt(o,t,index_sequence_for<A...>{});return o;}
template<typename T,typename O>auto& operator<<(O&o,T a){o<<"{";for(auto b:a)o<<b<<", ";return o<<"}";}
#define db(x...) cerr << "\033[92m" << "[" #x "]: ", [](auto... args) { ((cerr << args << ", "),...) << "\033[0m" << "\n"; }(x)
#else
#define db(...)
#endif
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
template<class T>
using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using vi = vector<int>;
mt19937 mrand(random_device{}());
ll rnd(ll l, ll r) { return l + mrand() % (r - l + 1);}
ll qry(ll x) { //PNK
char c = 'P';
if(x == 1) c = 'N';
else if (x == 2) c = 'K';
cout << c << endl;
cin >> c;
ll res = 0;
if(c == 'N') res = 1;
else if(c == 'K') res = 2;
ll f = 0;
if(x == 0 && res == 1) f = -1;
if(x == 1 && res == 2) f = -1;
if(x == 2 && res == 0) f = -1;
if(x == 1 && res == 0) f = 1;
if(x == 2 && res == 1) f = 1;
if(x == 0 && res == 2) f = 1;
if(f == 1) cout << "P" << endl;
else if(f == -1) cout << "N" << endl;
if(f != 0) cin >> c;
return res;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
string name, s; cin >> name;
ll n, t; cin >> n >> t;
map<string, pll> mp2t3 = {
{"000", {0, 0}},
{"001", {0, 1}},
{"010", {0, 2}},
{"011", {1, 0}},
{"100", {1, 1}},
{"101", {1, 2}},
{"110", {2, 0}},
{"111", {2, 1}}
};
map<pll, string> mp3t2;
for(auto [a, b] : mp2t3) mp3t2[b] = a;
while(t--) {
cin >> s;
if(n < 1000) {
string ans;
for(ll i = 0 ; i < n ; ++i) {
ll res = qry(s[i]-'0');
ans += (char)(res+'0');
}
cout << "! " << ans << endl;
continue;
}
s += "0";
vector<ll> v;
for(ll i = 0 ; i < 5001 ; i += 3) {
pll xd = mp2t3[s.substr(i, 3)];
v.emplace_back(xd.F); v.emplace_back(xd.S);
}
vector<ll> shift(3);
for(ll i = 0 ; i < sz(v) ; ++i) {
shift[(3 + i - v[i]) % 3]++;
}
ll best = 0;
if(shift[1] > shift[best]) best = 1;
if(shift[2] > shift[best]) best = 2;
ll sh = qry(best);
vector<ll> odp;
for(ll i = 0 ; i < sz(v) ; ++i) {
odp.emplace_back(qry((v[i]+best)%3));
}
string ans;
for(ll i = 0 ; i < sz(odp) ; i += 2) ans += mp3t2[{ (3 - sh + odp[i]) % 3, ( 3 - sh + odp[i+1]) % 3}];
ans.pop_back();
cout << "! " << ans << endl;
}
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #include <bits/stdc++.h> #include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; #define DEBUG #ifdef DEBUG template<typename T1,typename T2>auto& operator<<(ostream&o,pair<T1,T2>a){return o<<"("<<a.first<<", "<<a.second<<")";} template<typename T,size_t...I>void pt(ostream&o,T t,index_sequence<I...>){o<<"(";(...,(o<<(I?", ":"")<< get<I>(t)));o<<")";} template<typename...A>auto& operator<<(ostream&o,tuple<A...>t){pt(o,t,index_sequence_for<A...>{});return o;} template<typename T,typename O>auto& operator<<(O&o,T a){o<<"{";for(auto b:a)o<<b<<", ";return o<<"}";} #define db(x...) cerr << "\033[92m" << "[" #x "]: ", [](auto... args) { ((cerr << args << ", "),...) << "\033[0m" << "\n"; }(x) #else #define db(...) #endif #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define F first #define S second template<class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; using ll = long long; using ld = long double; using pll = pair<ll,ll>; using vi = vector<int>; mt19937 mrand(random_device{}()); ll rnd(ll l, ll r) { return l + mrand() % (r - l + 1);} ll qry(ll x) { //PNK char c = 'P'; if(x == 1) c = 'N'; else if (x == 2) c = 'K'; cout << c << endl; cin >> c; ll res = 0; if(c == 'N') res = 1; else if(c == 'K') res = 2; ll f = 0; if(x == 0 && res == 1) f = -1; if(x == 1 && res == 2) f = -1; if(x == 2 && res == 0) f = -1; if(x == 1 && res == 0) f = 1; if(x == 2 && res == 1) f = 1; if(x == 0 && res == 2) f = 1; if(f == 1) cout << "P" << endl; else if(f == -1) cout << "N" << endl; if(f != 0) cin >> c; return res; } int main() { cin.tie(0)->sync_with_stdio(0); string name, s; cin >> name; ll n, t; cin >> n >> t; map<string, pll> mp2t3 = { {"000", {0, 0}}, {"001", {0, 1}}, {"010", {0, 2}}, {"011", {1, 0}}, {"100", {1, 1}}, {"101", {1, 2}}, {"110", {2, 0}}, {"111", {2, 1}} }; map<pll, string> mp3t2; for(auto [a, b] : mp2t3) mp3t2[b] = a; while(t--) { cin >> s; if(n < 1000) { string ans; for(ll i = 0 ; i < n ; ++i) { ll res = qry(s[i]-'0'); ans += (char)(res+'0'); } cout << "! " << ans << endl; continue; } s += "0"; vector<ll> v; for(ll i = 0 ; i < 5001 ; i += 3) { pll xd = mp2t3[s.substr(i, 3)]; v.emplace_back(xd.F); v.emplace_back(xd.S); } vector<ll> shift(3); for(ll i = 0 ; i < sz(v) ; ++i) { shift[(3 + i - v[i]) % 3]++; } ll best = 0; if(shift[1] > shift[best]) best = 1; if(shift[2] > shift[best]) best = 2; ll sh = qry(best); vector<ll> odp; for(ll i = 0 ; i < sz(v) ; ++i) { odp.emplace_back(qry((v[i]+best)%3)); } string ans; for(ll i = 0 ; i < sz(odp) ; i += 2) ans += mp3t2[{ (3 - sh + odp[i]) % 3, ( 3 - sh + odp[i+1]) % 3}]; ans.pop_back(); cout << "! " << ans << endl; } return 0; } |
English