QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#604808#7510. Independent SetcjxTL 0ms0kbC++201.7kb2024-10-02 14:01:242024-10-02 14:01:25

Judging History

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

  • [2024-10-02 14:01:25]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-02 14:01:24]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
long long read(){
	long long x=0,f=1;char ch=getchar();
	while(!isdigit(ch))
	{if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
void write(long long x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
const int N=4010;
int n;
int edge[N][N],sum;
int a[N],b[N],e[N],ta,tb,te;
ll cnt=0;
void ask(){
	tb=0;
	printf("? %d",ta);
	for(int i=0;i<ta;i++){
		putchar(' ');write(a[i]);cnt++;
	}
	puts("");
	fflush(stdout);
	for(register int i=0;i<ta;i++){
		b[tb++]=read();
	}
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(register int i=1;i<=n;i++){
		for(register int j=1;j<=n;j++){
			edge[i][j]=-1;
		}
	}
	for(register int i=1;i<=n;i++){
		ta=0;a[ta++]=i;a[ta++]=i;
		edge[i][i]=b[1];
	}
	for(register int i=1;i<n;i++){
		int lst=i;
		while(1){
			ta=0;a[ta++]=i;
			for(register int j=lst+1;j<=n;j++){
				if(edge[i][j]==-1){
					a[ta++]=i;
				}
			}
			if(ta==1)break;
			ask();
			te=0;e[te++]=i;
			for(register int j=1;j<ta;j++){
				if(!b[j]){
					for(int k=0;k<te;k++)edge[a[j]][e[k]]=edge[e[k]][a[j]]=0;
					e[te++]=a[j];
				}
				else if(te==1){
					edge[i][a[j]]=edge[a[j]][i]=b[j];
				}
			}
			if(te>1)lst=e[1];
			if(cnt>176000)return 0;
		}
	}
	for(register int i=1;i<=n;i++){
		for(register int j=i;j<=n;j++){
			sum+=edge[i][j];
		}
	}
	printf("! %d",sum);
	for(register int i=1;i<=n;i++){
		for(register int j=i;j<=n;j++){
			for(register int k=1;k<=edge[i][j];k++){
				putchar(' ');write(i);
				putchar(' ');write(j);
			}
		}
	}
	puts("");
	fflush(stdout);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

4
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 ...

output:

? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
? 4 1 1 1 1
...

result: