Language: C++

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <cctype>
#include <cmath>
#include <vector>
#include <sstream>
#include <bitset>
#include <deque>
#include <iomanip>
using namespace std;
#define pr(x) cout << #x << " = " << x << endl;
#define bug cout << "bugbug" << endl;
#define ppr(x, y) printf("(%d, %d)\n", x, y);
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define SQR(a) ((a)*(a))
#define PCUT puts("\n---------------")

typedef long long ll;
typedef double DBL;
typedef pair<int, int> P;
typedef unsigned int uint;
const int MOD = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 4e3 + 4;
const int maxm = 1e4 + 4;
const double pi = acos(-1.0);
int A, B, n;
int kind[maxn], result[maxn], cnt[2];
char s[maxn];
int main(){
//必须编译过才能交
	int ik, i, j, k, kase;
	scanf("%d%d", &A, &B);
	int tot = (A+B) * 2;
	int maxv = max((B*B+3*B+2*A-4) / 2, (B+3)*B/2);
	if (tot < maxv || A <= B){
		printf("Impossible");
		fflush(stdout);
		return 0;
	} 
	n = A + B;
	memset(kind, -1, sizeof kind);
	bool ok = false;
	int cur = n - 1;
	while(!ok){
		cnt[0] = cnt[1] = 0;
		for (i = 0; i < n; ++i){
			if (kind[i] != -1) continue;
			printf("? %d %d\n", i, cur);
			fflush(stdout);
			scanf("%s", s);
			result[i] = s[0] == 'Y' ? 1 : 0;
			cnt[result[i]]++;
			if (cnt[result[i]] > B){
				if (result[i] == 1) ok = true, A--, kind[cur] = 1;
				else B--, kind[cur] = 0;
				for (j = 0; j < i; ++j)
					if (kind[j] == -1 && result[j] != result[i]){
						kind[j] = 0;
						B--;
					}
			}
		}
		if (B == 0){
			for (i = 0; i < n; ++i) if (kind[i] == -1 ) kind[i] = 1;
			break;
		}
	}
	if (kind[cur] == 1){
		for (int i = 0 ; i < n; ++i)
			if (kind[i] == -1){
				printf("? %d %d\n", cur, i);
				fflush(stdout);
				scanf("%s", s);
				kind[i] = s[0] == 'Y' ? 1 : 0;
			}
	}
	printf("! ");
	for (i = 0; i < n; ++i) printf("%d", kind[i]);
	printf("\n");
	fflush(stdout);
	return 0;
}
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <cctype>
#include <cmath>
#include <vector>
#include <sstream>
#include <bitset>
#include <deque>
#include <iomanip>
using namespace std;
#define pr(x) cout << #x << " = " << x << endl;
#define bug cout << "bugbug" << endl;
#define ppr(x, y) printf("(%d, %d)\n", x, y);
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define SQR(a) ((a)*(a))
#define PCUT puts("\n---------------")

typedef long long ll;
typedef double DBL;
typedef pair<int, int> P;
typedef unsigned int uint;
const int MOD = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 4e3 + 4;
const int maxm = 1e4 + 4;
const double pi = acos(-1.0);
int A, B, n;
int kind[maxn], result[maxn], cnt[2];
char s[maxn];
int main(){
//必须编译过才能交
	int ik, i, j, k, kase;
	scanf("%d%d", &A, &B);
	int tot = (A+B) * 2;
	int maxv = max((B*B+3*B+2*A-4) / 2, (B+3)*B/2);
	if (tot < maxv || A <= B){
		printf("Impossible");
		fflush(stdout);
		return 0;
	} 
	n = A + B;
	memset(kind, -1, sizeof kind);
	bool ok = false;
	int cur = n - 1;
	while(!ok){
		cnt[0] = cnt[1] = 0;
		for (i = 0; i < n; ++i){
			if (kind[i] != -1) continue;
			printf("? %d %d\n", i, cur);
			fflush(stdout);
			scanf("%s", s);
			result[i] = s[0] == 'Y' ? 1 : 0;
			cnt[result[i]]++;
			if (cnt[result[i]] > B){
				if (result[i] == 1) ok = true, A--, kind[cur] = 1;
				else B--, kind[cur] = 0;
				for (j = 0; j < i; ++j)
					if (kind[j] == -1 && result[j] != result[i]){
						kind[j] = 0;
						B--;
					}
			}
		}
		if (B == 0){
			for (i = 0; i < n; ++i) if (kind[i] == -1 ) kind[i] = 1;
			break;
		}
	}
	if (kind[cur] == 1){
		for (int i = 0 ; i < n; ++i)
			if (kind[i] == -1){
				printf("? %d %d\n", cur, i);
				fflush(stdout);
				scanf("%s", s);
				kind[i] = s[0] == 'Y' ? 1 : 0;
			}
	}
	printf("! ");
	for (i = 0; i < n; ++i) printf("%d", kind[i]);
	printf("\n");
	fflush(stdout);
	return 0;
}


Compiler output:
a.cc:122:11: error: redefinition of 'const int MOD'
  122 | const int MOD = 1e9 + 7;
      |           ^~~
a.cc:30:11: note: 'const int MOD' previously defined here
   30 | const int MOD = 1e9 + 7;
      |           ^~~
a.cc:123:11: error: redefinition of 'const int inf'
  123 | const int inf = 0x3f3f3f3f;
      |           ^~~
a.cc:31:11: note: 'const int inf' previously defined here
   31 | const int inf = 0x3f3f3f3f;
      |           ^~~
a.cc:124:10: error: redefinition of 'const ll INF'
  124 | const ll INF = 0x3f3f3f3f3f3f3f3f;
      |          ^~~
a.cc:32:10: note: 'const ll INF' previously defined here
   32 | const ll INF = 0x3f3f3f3f3f3f3f3f;
      |          ^~~
a.cc:125:11: error: redefinition of 'const int maxn'
  125 | const int maxn = 4e3 + 4;
      |           ^~~~
a.cc:33:11: note: 'const int maxn' previously defined here
   33 | const int maxn = 4e3 + 4;
      |           ^~~~
a.cc:126:11: error: redefinition of 'const int maxm'
  126 | const int maxm = 1e4 + 4;
      |           ^~~~
a.cc:34:11: note: 'const int maxm' previously defined here
   34 | const int maxm = 1e4 + 4;
      |           ^~~~
a.cc:127:14: error: redefinition of 'const double pi'
  127 | const double pi = acos(-1.0);
      |              ^~
a.cc:35:14: note: 'const double pi' previously defined here
   35 | const double pi = acos(-1.0);
      |              ^~
a.cc:128:5: error: redefinition of 'int A'
  128 | int A, B, n;
      |     ^
a.cc:36:5: note: 'int A' previously declared here
   36 | int A, B, n;
      |     ^
a.cc:128:8: error: redefinition of 'int B'
  128 | int A, B, n;
      |        ^
a.cc:36:8: note: 'int B' previously declared here
   36 | int A, B, n;
      |        ^
a.cc:128:11: error: redefinition of 'int n'
  128 | int A, B, n;
      |           ^
a.cc:36:11: note: 'int n' previously declared here
   36 | int A, B, n;
      |           ^
a.cc:129:5: error: redefinition of 'int kind [4004]'
  129 | int kind[maxn], result[maxn], cnt[2];
      |     ^~~~
a.cc:37:5: note: 'int kind [4004]' previously declared here
   37 | int kind[maxn], result[maxn], cnt[2];
      |     ^~~~
a.cc:129:17: error: redefinition of 'int result [4004]'
  129 | int kind[maxn], result[maxn], cnt[2];
      |                 ^~~~~~
a.cc:37:17: note: 'int result [4004]' previously declared here
   37 | int kind[maxn], result[maxn], cnt[2];
      |                 ^~~~~~
a.cc:129:31: error: redefinition of 'int cnt [2]'
  129 | int kind[maxn], result[maxn], cnt[2];
      |                               ^~~
a.cc:37:31: note: 'int cnt [2]' previously declared here
   37 | int kind[maxn], result[maxn], cnt[2];
      |                               ^~~
a.cc:130:6: error: redefinition of 'char s [4004]'
  130 | char s[maxn];
      |      ^
a.cc:38:6: note: 'char s [4004]' previously declared here
   38 | char s[maxn];
      |      ^
a.cc:131:5: error: redefinition of 'int main()'
  131 | int main(){
      |     ^~~~
a.cc:39:5: note: 'int main()' previously defined here
   39 | int main(){
      |     ^~~~