Codeforces Round 973 (Div. 2) C

#include <bits/stdc++.h>
using namespace std;
int T;
int n;
struct edge
{
	int pre;
	int nxt;
	int val;
}e[110];
int cnt = 0,rt;
int temp;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		memset(e,0,sizeof(e));
		int ed = 0;
		cnt = 0,rt = 0;
		scanf("%d",&n);
		int lc = 1,rc = 1;
		printf("? 0");
		printf("\n");
		fflush(stdout) ;
		scanf("%d",&temp);
		int flag = 0;
		if(temp == 1)e[++cnt].val = 0,rt = cnt,e[cnt].pre = -1,e[cnt].nxt = -1;
		else 
		{
			printf("! ");
			for(int i = 1;i <= n;i++)printf("1");
			printf("\n");
			fflush(stdout) ;
			flag = 1;
		}
		if(flag == 1)
		{
			continue;
		}
		ed = rt;
		ed = rt;
		for(int k = 2;k <= n;k++)
		{
			if(lc == 1)
			{
				e[++cnt].val = 0;
				e[cnt].nxt = rt;
				e[cnt].pre = -1;
				e[rt].pre = cnt;
				printf("? 0");
				for(int i = rt;i != -1;i = e[i].nxt)
					printf("%d",e[i].val);
				printf("\n");
				fflush(stdout) ;
				scanf("%d",&temp);
				if(temp == 1)
				{
					rt = cnt;
					continue;	
				}
				else
				{
					e[cnt].val = 1;
					printf("? 1");
					for(int i = rt;i != -1;i = e[i].nxt)
						printf("%d",e[i].val);
					printf("\n");
					fflush(stdout) ;
					scanf("%d",&temp);
					if(temp == 1)
					{
						rt = cnt;
						continue;
					}
					else
					{
						lc = 0;
						k--;
						continue;
					}
				}
			}
			else
			{
				while(e[ed].nxt != -1)ed = e[ed].nxt;
				e[++cnt].val = 0;
				e[cnt].pre = ed;
				e[cnt].nxt = -1;
				e[ed].nxt = cnt;
				printf("? ");
				for(int i = rt;i != -1;i = e[i].nxt)
					printf("%d",e[i].val);
				printf("\n");
				fflush(stdout) ;
				scanf("%d",&temp);
				if(temp == 1)
				{
					ed = cnt;
					continue;
				}
				else
				{
					e[cnt].val = 1;
					ed = cnt;
					continue;
				}
			}
		}
		printf("! ");
		for(int i = rt;i != -1;i = e[i].nxt)printf("%d",e[i].val);
		printf("\n");
		fflush(stdout) ;
	}	
	return 0;
} 
posted @ 2024-09-23 00:17  kanade16  阅读(12)  评论(0编辑  收藏  举报