#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<long long,long long>
using namespace std;
using ll = long long;
using ld = long double;
constexpr int SIZE = 5e3+3;
bool tab[SIZE];
bool ans[SIZE];
int SOLVE(int n, bool my_turn){
char c;
for (int i=0; i<n; i++) {
cin >> c;
if (c == '1') tab[i] = 1;
else tab[i] = 0;
}
int AP = 0;
int BP = 0;
for (int i=0; i<2*n; i++){
if (my_turn ^ (i%2)){
cout << 'P' << endl;
cin >> c;
if (c == 'P') {
ans[i/2] = 0;
continue;
}
ans[i/2] = 1;
if (AP >= BP) BP ++;
else AP ++;
continue;
}
if (!tab[i/2]) {
cout << 'P' << endl;
cin >> c;
continue;
}
if (BP >= AP){
cout << 'N' << endl;
cin >> c;
AP ++;
}else {
cout << 'K' << endl;
cin >> c;
BP ++;
}
}
cout << "! ";
for (int i=0; i<n; i++) cout << ans[i];
cout << endl;
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string who;
cin >> who;
int n, t;
cin >> n >> t;
bool my_turn = 0;
if (who == "Algosia") my_turn = 1;
while (t--) SOLVE(n, my_turn);
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 | #include <bits/stdc++.h> #define F first #define S second #define pii pair<long long,long long> using namespace std; using ll = long long; using ld = long double; constexpr int SIZE = 5e3+3; bool tab[SIZE]; bool ans[SIZE]; int SOLVE(int n, bool my_turn){ char c; for (int i=0; i<n; i++) { cin >> c; if (c == '1') tab[i] = 1; else tab[i] = 0; } int AP = 0; int BP = 0; for (int i=0; i<2*n; i++){ if (my_turn ^ (i%2)){ cout << 'P' << endl; cin >> c; if (c == 'P') { ans[i/2] = 0; continue; } ans[i/2] = 1; if (AP >= BP) BP ++; else AP ++; continue; } if (!tab[i/2]) { cout << 'P' << endl; cin >> c; continue; } if (BP >= AP){ cout << 'N' << endl; cin >> c; AP ++; }else { cout << 'K' << endl; cin >> c; BP ++; } } cout << "! "; for (int i=0; i<n; i++) cout << ans[i]; cout << endl; return 0; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string who; cin >> who; int n, t; cin >> n >> t; bool my_turn = 0; if (who == "Algosia") my_turn = 1; while (t--) SOLVE(n, my_turn); return 0;} |
English