QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#775628#9783. Duloc Networkucup-team5697#WA 6ms4248kbC++233.7kb2024-11-23 16:21:052024-11-23 16:21:06

Judging History

你现在查看的是最新测评结果

  • [2024-11-23 16:21:06]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:4248kb
  • [2024-11-23 16:21:05]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<string>
#include<bitset>
#include<numeric>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=205;
const int N=200;
const int INF=0x3f3f3f3f;
const long long LINF=0x3f3f3f3f3f3f3f3f;
int n,k,cnt=0;
int deg[MAXN];
basic_string <int> s[MAXN];
int v[MAXN];
bool vis[MAXN];
namespace Q{
	int cnt=0;
	int n,m;
	bool e[MAXN][MAXN];
	char s[MAXN];
	int pre[MAXN];
	inline int find(int x){
		return pre[x]^x?pre[x]=find(pre[x]):x;
	}
	inline void start(){
		scanf("%d%d",&n,&m);
		iota(pre+1,pre+1+n,1);
		for(int i=1;i<=m;i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			e[x][y]=e[y][x]=1;
			pre[find(x)]=find(y);
		}
		for(int i=1;i<=n;i++)
		{
			if(find(i)!=find(1)){
				puts("answer is disconnected!");
				return ;
			}
		}
		puts("answer is connected!");
	}
	inline int qry(){
		cnt++;
		printf("%s\n",s+1);
		int res=0;
		for(int i=1;i<=n;i++)
		{
			if(s[i]=='1'){
				continue;
			}
			for(int j=1;j<=n;j++)
			{
				if(e[i][j]&&s[j]=='1'){
					res++;
				}
			}
		}
		printf("%d\n",res);
		return res;
	}
}
inline int query(basic_string <int> qry){
	memset(vis,false,sizeof(bool)*(n+1));
	for(int x:qry)
	{
		vis[x]=true;
	}
	putchar('?');
	putchar(' ');
	for(int i=1;i<=n;i++)
	{
		putchar(vis[i]+'0');
		#ifdef LOCAL
		Q::s[i]=vis[i]+'0';
		#endif
	}
	putchar('\n');
	fflush(stdout);
	int res;
	#ifdef LOCAL
	res=Q::qry();
	#else
	scanf("%d",&res);
	#endif
	// printf("!%d\n",res);
	res=-res;
	for(int x:qry)
	{
		res+=deg[x];
	}
	// printf("real %d\n",res>>1);
	return res>>1;
}
void divide(int l,int r){
	if(l+1==r){
		basic_string <int> qry=s[l]+s[r];
		int now=query(qry);
			// puts("join");
			// for(int x:s[l])printf("(%d)",x);puts("");
			// for(int x:s[r])printf("(%d)",x);puts("");
		if(now!=v[l]+v[r]){
			// puts("join!");
			// printf("inside %d\n",now);
			s[l]+=s[r];
			s[r].clear();
			v[l]=now;
			return ;
		}
		puts("! 0");
		fflush(stdout);
		exit(0);
	}
	int pl=l+(r-l+1)/3,pr=r-(r-l+1)/3;
	basic_string <int> qry;
	int sum=0;
	for(int i=l;i<=pr;i++)
	{
		qry+=s[i];
		sum+=v[i];
	}
	// puts("calc");
	// for(int i=l;i<=r;i++){for(int x:s[i])printf("(%d)",x);puts("");}
	if(query(qry)-sum){
		// puts("l!!!!!!!!!!!");
		divide(l,pr);
		return ;
	}
	qry.clear();
	sum=0;
	for(int i=pl;i<=r;i++)
	{
		qry+=s[i];
		sum+=v[i];
	}
	if(query(qry)-sum){
		// puts("r!!!!!!!!!!!");
		divide(pl,r);
		return ;
	}
	for(int i=pr+1;i<=r;i++)
	{
		swap(s[i],s[pl+(i-pr-1)]);
	}
	divide(l,l+(pr-l)+(r-pl)-1);
}
inline void calc(){
	cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(!s[i].empty()){
			cnt++;
			s[i].swap(s[cnt]);
			swap(v[i],v[cnt]);
		}
	}
	divide(1,cnt);
}
inline void solve(){
	#ifdef LOCAL
	Q::start();
	#endif
	scanf("%d",&n);
	k=n;
	for(int i=1;i<=n;i++)
	{
		putchar('?');
		putchar(' ');
		for(int j=1;j<=n;j++)
		{
			putchar((i==j)+'0');
			#ifdef LOCAL
			Q::s[j]=(i==j)+'0';
			#endif
		}
		putchar('\n');
		fflush(stdout);
		#ifdef LOCAL
		deg[i]=Q::qry();
		printf("deg[%d]=%d\n",i,deg[i]);
		#else
		scanf("%d",&deg[i]);
		#endif
		s[i].push_back(i);
	}
	for(int i=1;i<n;i++)
	{
		calc();
	}
	puts("! 1");
	fflush(stdout);
	#ifdef LOCAL
	printf("qry times:%d\n",Q::cnt);
	#endif
}
signed main(){
	#ifdef LOCAL
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
	atexit([](){fprintf(stderr,"%.3lfs\n",(double)clock()/CLOCKS_PER_SEC);});
	#endif
	solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3680kb

input:

4
1
3
2
2
1
2
2
1
1
0

output:

? 1000
? 0100
? 0010
? 0001
? 1110
? 1100
? 1100
? 1110
? 1110
? 1111
! 1

result:

ok Correct answer with 10 queries.

Test #2:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

2
0
0
0

output:

? 10
? 01
? 11
! 0

result:

ok Correct answer with 3 queries.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

4
1
3
2
2
1
2
2
1
1
0

output:

? 1000
? 0100
? 0010
? 0001
? 1110
? 1100
? 1100
? 1110
? 1110
? 1111
! 1

result:

ok Correct answer with 10 queries.

Test #4:

score: 0
Accepted
time: 1ms
memory: 4052kb

input:

2
0
0
0

output:

? 10
? 01
? 11
! 0

result:

ok Correct answer with 3 queries.

Test #5:

score: -100
Wrong Answer
time: 6ms
memory: 4248kb

input:

50
3
1
1
1
1
4
3
1
1
2
3
3
2
1
2
4
3
1
1
1
2
4
1
3
1
4
3
2
2
2
4
2
2
1
1
2
1
2
4
1
1
3
3
3
6
2
1
3
2
3
14
16
17
14
12
10
10
12
7
6
5
4
2
2
14
16
17
14
12
8
7
6
5
5
4
4
3
3
3
14
15
16
16
12
11
7
9
11
9
6
5
5
5
13
15
17
15
15
12
10
8
7
5
3
2
2
2
13
15
17
14
10
13
9
6
5
4
3
2
2
13
15
17
16
13
8
8
7
6
7...

output:

? 10000000000000000000000000000000000000000000000000
? 01000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000
? 00010000000000000000000000000000000000000000000000
? 00001000000000000000000000000000000000000000000000
? 000001000000000000000000000000000...

result:

wrong answer Too many queries.