#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
void decode(string& s, int seed);
int play(char me, char them);
int main()
{
bool bajt;
{
string s;
cin>>s;
bajt = s[0] == 'B';
}
int seed = bajt ? 92 : 12345;
int seed2 =!bajt? 92 : 12345;
int n, t;
cin>>n>>t;
while(t--) {
string s, t;
t.resize(n);
cin>>s;
decode(s, seed);
int score = 0;
int my = 0, their = 0;
while((my < n) && (their < n)) {
// cout<<score<<' '<<my<<' '<<their<<"\n";
if(score == 0) {
char msg;
if(s[my++] == '0')
msg = 'P'; //0
else if((my < n) && (s[my++] == '1'))
msg = 'K'; //11
else
msg = 'N'; //1?
cout<<msg<<endl;
char other;
cin>>other;
if(other == 'P')
t[their++] = '0';
else if(other == 'K') {
t[their++] = '1';
t[their++] = '1';
} else if(other == 'N') {
t[their++] = '1';
if(their < n)
t[their++] = '0';
}
score += play(msg, other);
} else {
bool pass = (my > their) || ((my == their) && bajt);
// cout<<pass<<";"<<endl;
if(pass) {
char msg = (score==-1?'P':'K');
cout<<msg<<endl;
char other;
cin>>other;
t[their++] = other == 'P' ? '0' : '1';
score += play(msg, other);
} else {
char msg = s[my++] == '0' ? 'P' : 'K';
cout<<msg<<endl;
char other;
cin>>other;
score += play(msg, other);
}
}
}
while(my < n) {
// cout<<"!"<<score<<' '<<my<<' '<<their<<"\n";
char msg;
if(score == 0) {
if(s[my++] == '0')
msg = 'P'; //0
else if((my < n) && (s[my++] == '1'))
msg = 'K'; //11
else
msg = 'N'; //1?
} else {
msg = s[my++] == '0' ? 'P' : 'K';
}
cout<<msg<<endl;
char other;
cin>>other;
score += play(msg, other);
}
while(their < n) {
// cout<<"$"<<score<<' '<<my<<' '<<their<<"\n";
char msg = (score!=1?'P':'K');
cout<<msg<<endl;
char other;
cin>>other;
if(score == 0) {
if(other == 'P')
t[their++] = '0';
else if(other == 'K') {
t[their++] = '1';
t[their++] = '1';
} else if(other == 'N') {
t[their++] = '1';
if(their < n)
t[their++] = '0';
}
} else
t[their++] = other == 'P' ? '0' : '1';
score += play(msg, other);
}
decode(t, seed2);
cout<<"! "<<t<<endl;
}
}
void decode(string& s, int seed) {
srand(seed);
for(auto& x : s) {
x ^= rand() & 1;
}
}
int play(char me, char them) {
if(me == them)
return 0;
if((me == 'P') && (them == 'K')
|| (me == 'K') && (them == 'N')
|| (me == 'N') && (them == 'P'))
return 1;
return -1;
}
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | #include <iostream> #include <vector> #include <cstdlib> using namespace std; void decode(string& s, int seed); int play(char me, char them); int main() { bool bajt; { string s; cin>>s; bajt = s[0] == 'B'; } int seed = bajt ? 92 : 12345; int seed2 =!bajt? 92 : 12345; int n, t; cin>>n>>t; while(t--) { string s, t; t.resize(n); cin>>s; decode(s, seed); int score = 0; int my = 0, their = 0; while((my < n) && (their < n)) { // cout<<score<<' '<<my<<' '<<their<<"\n"; if(score == 0) { char msg; if(s[my++] == '0') msg = 'P'; //0 else if((my < n) && (s[my++] == '1')) msg = 'K'; //11 else msg = 'N'; //1? cout<<msg<<endl; char other; cin>>other; if(other == 'P') t[their++] = '0'; else if(other == 'K') { t[their++] = '1'; t[their++] = '1'; } else if(other == 'N') { t[their++] = '1'; if(their < n) t[their++] = '0'; } score += play(msg, other); } else { bool pass = (my > their) || ((my == their) && bajt); // cout<<pass<<";"<<endl; if(pass) { char msg = (score==-1?'P':'K'); cout<<msg<<endl; char other; cin>>other; t[their++] = other == 'P' ? '0' : '1'; score += play(msg, other); } else { char msg = s[my++] == '0' ? 'P' : 'K'; cout<<msg<<endl; char other; cin>>other; score += play(msg, other); } } } while(my < n) { // cout<<"!"<<score<<' '<<my<<' '<<their<<"\n"; char msg; if(score == 0) { if(s[my++] == '0') msg = 'P'; //0 else if((my < n) && (s[my++] == '1')) msg = 'K'; //11 else msg = 'N'; //1? } else { msg = s[my++] == '0' ? 'P' : 'K'; } cout<<msg<<endl; char other; cin>>other; score += play(msg, other); } while(their < n) { // cout<<"$"<<score<<' '<<my<<' '<<their<<"\n"; char msg = (score!=1?'P':'K'); cout<<msg<<endl; char other; cin>>other; if(score == 0) { if(other == 'P') t[their++] = '0'; else if(other == 'K') { t[their++] = '1'; t[their++] = '1'; } else if(other == 'N') { t[their++] = '1'; if(their < n) t[their++] = '0'; } } else t[their++] = other == 'P' ? '0' : '1'; score += play(msg, other); } decode(t, seed2); cout<<"! "<<t<<endl; } } void decode(string& s, int seed) { srand(seed); for(auto& x : s) { x ^= rand() & 1; } } int play(char me, char them) { if(me == them) return 0; if((me == 'P') && (them == 'K') || (me == 'K') && (them == 'N') || (me == 'N') && (them == 'P')) return 1; return -1; } |
English