手动SPJ

前言

题目为内部题库联赛模拟测试17第三题,gjk.cpp为AC代码,lsx.cpp为被检测代码

已经被拍挂的名单:

\(DarthVictor\)

\(Midoria\)

\(B041016\)

\(youxam\)

\(HEOI \text{动动}\)

check

#include<bits/stdc++.h>
#define re register
using namespace std;
const int lzw=2e5+3;
int n,a[lzw],g[lzw],l[lzw];
int num[lzw],Max;
bool flag;
int main(){
	freopen("check.out","w",stdout);
	freopen("in.in","r",stdin);
	scanf("%d",&n);
	for(re int i=1;i<=n;i++) scanf("%d",&a[i]);
	system("./gjk");
//	fclose(stdin);
	freopen("gjk.out","r",stdin);
	int gjk;
	scanf("%d",&gjk);
//	cin>>gjk
	if(gjk!=-1) for(re int i=1;i<=n;i++) scanf("%d",&g[i]);
//	fclose(stdin);
	system("./lsx");
	freopen("lsx.out","r",stdin);
	int lsx;
	scanf("%d",&lsx);
	if(lsx!=-1) for(re int i=1;i<=n;i++) scanf("%d",&l[i]);
//	cout<<gjk<<' '<<lsx<<endl;
	if(lsx!=gjk) return cout<<"最大的不一样WA1"<<endl,0;
	if(lsx==-1) return cout<<"AC"<<endl,0;
	memset(num,0,sizeof(num));
	for(re int i=1;i<=n;i++){
		if(a[i]&&a[i]!=g[i]) cout<<"凯爹出错WA2"<<endl,flag=1;
		num[g[i]]++;
		if(num[g[i]]>5) cout<<"凯爹出错WA3"<<endl,flag=1;
		if(g[i]<g[i-1]||abs(g[i]-g[i-1])>1) cout<<"凯爹出错WA4"<<endl,flag=1;
	}
	for(re int i=1;i<=gjk;i++) if(num[i]<2) cout<<"凯爹出错WA5"<<endl,flag=1;
	memset(num,0,sizeof(num));
	for(re int i=1;i<=n;i++){
		if(a[i]&&a[i]!=l[i]) cout<<"sir出错WA2"<<endl,flag=1;
		num[l[i]]++;
		if(num[l[i]]>5) cout<<"sir出错WA3"<<endl,flag=1;
		if(l[i]<l[i-1]||abs(l[i]>l[i-1])>1) cout<<"sir出错WA4"<<endl,flag=1;
	}
	for(re int i=1;i<=lsx;i++) if(num[i]<2) cout<<"sir出错WA5"<<endl,flag=1;
	if(!flag) cout<<"AC"<<endl;
}

run

#include<bits/stdc++.h>
using namespace std;
int main(){
	system("g++ check.cpp -o check");
	system("g++ gjk.cpp -o gjk -O2");
	system("g++ lsx.cpp -o lsx -O2");
	system("g++ data.cpp -o data");
	int cnt=0;
	while(++cnt){
		system("./data");
		system("./check");
		freopen("check.out","r",stdin);
		string s;
		cin>>s;
		if(s!="AC") return cout<<s<<endl,0;
		cout<<cnt<<' '<<s<<endl;
		if(cnt==10000) return 0;
	}
}

data

#include<bits/stdc++.h>
#define re register
#define rint register int
using namespace std;
vector<int> v;
int tag[200000];
const int maxn=1e2;
int main(){
	srand((unsigned int)(new char));
	freopen("in.in","w",stdout);
	rint n=rand()%maxn+5;
	printf("%d\n",n);
	for(rint i=rand()%3+1;i<=n;i+=rand()%3+2)
		tag[i]=1;
	for(rint i=1;i<=n;i++) tag[i]+=tag[i-1];
	tag[n+1]=tag[n]+1;
	for(rint i=2;i<=n;i++)
	{
		if(rand()%3) tag[i]=tag[i-1];
		if(rand()%3) tag[i]=tag[i+1];
	}
	for(rint i=2;i<=n;i++)
	{
		if(rand()%3) tag[i]=tag[i-1];
		if(rand()%3) tag[i]=tag[i+1];
	}
	for(rint i=1;i<=n;i++)
		if(rand()%4)
			tag[i]=0;
	for(rint i=1;i<=n;i++)
		if(rand()%2333==0)
			swap(tag[rand()%n+1],tag[rand()%n+1]);
	for(rint i=1;i<=n;i++)
		printf("%d ",tag[i]);
}

gjk.cpp

#include <cstdio>
const int maxn=2e5+10;
int dp[maxn][10];
int tmp[maxn];
int a[maxn];
void get(int wh,int hm){
	if(!wh)
		return;
	for(int i=1,now=tmp[wh];i<=hm;i++,now--)
		a[now]=a[tmp[wh]];
	if(dp[wh][hm]==1)
		a[tmp[wh-1]+1]=a[tmp[wh-1]];
	get(wh-1,dp[wh][hm]);
}
int n;
void solve(){
	int lst=1;
	int lsts=0;
	for(int i=1;i<=n;i++){
		if(!a[i]&&a[i-1]){
			lst=i;
			lsts=a[i-1];
		}
		if(!a[i]&&a[i+1]){
			int now=i-lst+1;
			int cz=a[i+1]-lsts-1;
			if(!cz){
				for(int j=i;j>=lst;j--)
					a[j]=lsts;
			}
			if(cz*5<now){
				int nowf=0;
				int s=a[i+1]-1;
				for(int j=i;j>=lst;j--){
					a[j]=s;
					nowf++;
					if(nowf==5){
						nowf=0;
						s--;
					}
				}
			}
			else{
				int tmp=now/cz;
				int d=now-tmp*cz;
				int s=a[i+1]-1;
				int ha=0;
				for(int j=i;j>=lst;j--){
					a[j]=s;
					ha++;
					if((ha==tmp&&a[i+1]-s>d)||ha==tmp+1){
						ha=0;
						s--;
					}
				}
			}
		}
	}
}
int main(){
	freopen("in.in","r",stdin);
	freopen("gjk.out","w",stdout);
	scanf("%d",&n);
	int cnt=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i])
			tmp[++cnt]=i;
	}
	dp[0][5]=1;
	for(int i=1;i<=cnt;i++){
		if(dp[i-1][1]){
			int cz=a[tmp[i]]-a[tmp[i-1]];
			int jl=tmp[i]-tmp[i-1];
			if(!cz){
				if(1+jl<=5&&!dp[i][1+jl])
					dp[i][1+jl]=1;
			}
			else{
				if((cz-1)*2+2<=jl&&(cz-1)*5+5>=jl)
					if(!dp[i][1])
						dp[i][1]=1;
				if((cz-1)*2+3<=jl&&(cz-1)*5+6>=jl)
					if(!dp[i][2])
						dp[i][2]=1;
				if((cz-1)*2+4<=jl&&(cz-1)*5+7>=jl)
					if(!dp[i][3])
						dp[i][3]=1;
				if((cz-1)*2+5<=jl&&(cz-1)*5+8>=jl)
					if(!dp[i][4])
						dp[i][4]=1;
				if((cz-1)*2+6<=jl&&(cz-1)*5+9>=jl)
					if(!dp[i][5])
						dp[i][5]=1;
			}
		}
		if(dp[i-1][2]){
			int cz=a[tmp[i]]-a[tmp[i-1]];
			int jl=tmp[i]-tmp[i-1];
			if(!cz){
				if(2+jl<=5&&!dp[i][2+jl])
					dp[i][2+jl]=2;
			}
			else{
				if((cz-1)*2+1<=jl&&(cz-1)*5+4>=jl)
					if(!dp[i][1])
						dp[i][1]=2;
				if((cz-1)*2+2<=jl&&(cz-1)*5+5>=jl)
					if(!dp[i][2])
						dp[i][2]=2;
				if((cz-1)*2+3<=jl&&(cz-1)*5+6>=jl)
					if(!dp[i][3])
						dp[i][3]=2;
				if((cz-1)*2+4<=jl&&(cz-1)*5+7>=jl)
					if(!dp[i][4])
						dp[i][4]=2;
				if((cz-1)*2+5<=jl&&(cz-1)*5+8>=jl)
					if(!dp[i][5])
						dp[i][5]=2;
			}
		}
		if(dp[i-1][3]){
			int cz=a[tmp[i]]-a[tmp[i-1]];
			int jl=tmp[i]-tmp[i-1];
			if(!cz){
				if(3+jl<=5&&!dp[i][3+jl])
					dp[i][3+jl]=3;
			}
			else{
				if((cz-1)*2+1<=jl&&(cz-1)*5+3>=jl)
					if(!dp[i][1])
						dp[i][1]=3;
				if((cz-1)*2+2<=jl&&(cz-1)*5+4>=jl)
					if(!dp[i][2])
						dp[i][2]=3;
				if((cz-1)*2+3<=jl&&(cz-1)*5+5>=jl)
					if(!dp[i][3])
						dp[i][3]=3;
				if((cz-1)*2+4<=jl&&(cz-1)*5+6>=jl)
					if(!dp[i][4])
						dp[i][4]=3;
				if((cz-1)*2+5<=jl&&(cz-1)*5+7>=jl)
					if(!dp[i][5])
						dp[i][5]=3;
			}
		}
		if(dp[i-1][4]){
			int cz=a[tmp[i]]-a[tmp[i-1]];
			int jl=tmp[i]-tmp[i-1];
			if(!cz){
				if(4+jl<=5&&!dp[i][4+jl])
					dp[i][4+jl]=4;
			}
			else{
				if((cz-1)*2+1<=jl&&(cz-1)*5+2>=jl)
					if(!dp[i][1])
						dp[i][1]=4;
				if((cz-1)*2+2<=jl&&(cz-1)*5+3>=jl)
					if(!dp[i][2])
						dp[i][2]=4;
				if((cz-1)*2+3<=jl&&(cz-1)*5+4>=jl)
					if(!dp[i][3])
						dp[i][3]=4;
				if((cz-1)*2+4<=jl&&(cz-1)*5+5>=jl)
					if(!dp[i][4])
						dp[i][4]=4;
				if((cz-1)*2+5<=jl&&(cz-1)*5+6>=jl)
					if(!dp[i][5])
						dp[i][5]=4;
			}
		}
		if(dp[i-1][5]){
			int cz=a[tmp[i]]-a[tmp[i-1]];
			int jl=tmp[i]-tmp[i-1];
			if(!cz){
				if(5+jl<=5&&!dp[i][5+jl])
					dp[i][5+jl]=5;
			}
			else{
				if((cz-1)*2+1<=jl&&(cz-1)*5+1>=jl)
					if(!dp[i][1])
						dp[i][1]=5;
				if((cz-1)*2+2<=jl&&(cz-1)*5+2>=jl)
					if(!dp[i][2])
						dp[i][2]=5;
				if((cz-1)*2+3<=jl&&(cz-1)*5+3>=jl)
					if(!dp[i][3])
						dp[i][3]=5;
				if((cz-1)*2+4<=jl&&(cz-1)*5+4>=jl)
					if(!dp[i][4])
						dp[i][4]=5;
				if((cz-1)*2+5<=jl&&(cz-1)*5+5>=jl)
					if(!dp[i][5])
						dp[i][5]=5;
			}
		}
		int bj=0;
		for(int j=1;j<=5;j++)
			bj|=dp[i][j];
		if(!bj){
			printf("-1");
			return 0;
		}
	}
	if(tmp[cnt]==n){
		int bj=0;
		for(int i=2;i<=5;i++)
			bj|=dp[cnt][i];
		if(!bj){
			printf("-1");
			return 0;
		}
	}
	for(int i=2;i<=5;i==5?(i=1):i++){
		if(dp[cnt][i]){
			if(i==1){
				printf("%d\n",(n-tmp[cnt]-1)/2+a[tmp[cnt]]);
				a[tmp[cnt]+1]=a[tmp[cnt]];
				int now=a[tmp[cnt]]+1;
				int nown=tmp[cnt]+2;
				for(int j=1;nown<=n;j++,nown++,now+=j&1)
					a[nown]=now;
				get(cnt,1);
				if(a[n]!=a[n-1])
					a[n]--;
			}
			else{
				int tmp_=(n-tmp[cnt])/2+a[tmp[cnt]];
				int now=a[tmp[cnt]]+1;
				int nown=tmp[cnt]+1;
				for(int j=1;nown<=n;j++,nown++,now+=j&1)
					a[nown]=now;
				get(cnt,i);
				if(a[n]!=a[n-1]&&a[n-1]){
					a[n]--;
					if(tmp[cnt]==n-1&&i==5){
						printf("-1");
						return 0;
					}
				}
				printf("%d\n",tmp_);
			}
			solve();
			for(int j=1;j<=n;j++)
				printf("%d ",a[j]);
			return 0;
		}
	}
	return 0;
}
posted @ 2020-10-15 16:51  DarthVictor  阅读(116)  评论(3编辑  收藏  举报
莫挨老子!