QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#529328#6399. Classic: Classical Problemsolar_express#WA 0ms3868kbC++141.5kb2024-08-24 12:01:412024-08-24 12:01:41

Judging History

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

  • [2024-08-24 12:01:41]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2024-08-24 12:01:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,p;
int o[220000];
int pd[220000];
int inv[220000];
int out[220000],otop;
int zan[2200],ztop=0;
int ans;
int power(long long a,long long b){
	long long RE=1;
	while(b>0){
		if(b&1)RE=RE*a%p;
		b>>=1;a=(a*a)%p;
	}
	return RE;
}
void init(){
	ans=0;
	otop=0;
	ztop=0;
	for(int i=0;i<=p;i++){
		pd[i]=0;
	}
	for(int i=1;i<p;i++){
		inv[i]=power(i,p-2);
	}
}
void sol(){
	scanf("%d%d",&n,&p);
	init();
	for(int i=1;i<=n;i++){
		//scanf("%d",&o[i]);
		o[i]=i-1;
		pd[o[i]]=1;
	}
	if(!pd[0]){
		puts("1 1");
		puts("0");
		return ;
	}
	if(p-n<=2000){
		for(int i=0;i<p;i++){
			if(!pd[i])zan[++ztop]=i;
		}
		for(int i=1;i<p;i++){
			int mex=p;
			for(int j=1;j<=ztop;j++){
				mex=min(mex,(int)(1ll*zan[j]*i%p));
			}
			if(mex>ans){
				ans=mex;
				otop=0;
				out[++otop]=i;
			}
			else if(mex==ans){
				out[++otop]=i;
			}
		}
		printf("%d %d\n",otop,ans);
		for(int i=1;i<=otop;i++){
			printf("%d ",out[i]);
		}printf("\n");
		return ;
	}
	else{
		for(int i=1;i<p;i++){
			int mex=1;
			for(int j=1;j<p;j++){
				int x=1ll*j*inv[i]%p;
				if(!pd[x]){
					mex=j;
					break;
				}
			}
			if(mex>ans){
				ans=mex;
				otop=0;
				out[++otop]=i;
			}
			else if(mex==ans){
				out[++otop]=i;
			}
		}
		printf("%d %d\n",otop,ans);
		for(int i=1;i<=otop;i++){
			printf("%d ",out[i]);
		}printf("\n");
		return ;
	}
}
int main(){
	int T;
	cin>>T;
	while(T--){
		sol();
	}
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3868kb

input:

3
2 3
0 2
3 5
2 3 4
3 5
0 2 3

output:

1 2
1 
1 1
0
1 3
1 

result:

wrong answer 2nd lines differ - expected: '2', found: '1 '