QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#459847#8830. Breaking BadlgvcWA 2ms12072kbC++142.5kb2024-06-30 14:47:382024-06-30 14:47:39

Judging History

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

  • [2024-06-30 14:47:39]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12072kb
  • [2024-06-30 14:47:38]
  • 提交

answer

#include <bits/stdc++.h>
int N,a[1009][1009],a2[1009][1009],p[1009],p2[1009],dp[1009][300][5],dp2[1009][300][5],
st[10],v2[5],vc[5],t1[1009],t2[1009];
void bf() {
	for(int i=1;i<=N;i++) p[i]=i;
}
bool tr(int aa,int b,int c,int d) {
	if(aa+c>N||b+d>N) return 0;
	c+=aa;d+=b;
	if((a[aa][b]+a[c][d]-a[aa][d]-a[c][b])%5!=0) return 1;
	return 0;
}
signed main(void) {
	//freopen("m.in","r",stdin);
	srand(time(NULL));
	scanf("%d",&N);
	for(int i=1;i<=N;i++) {
		for(int j=1;j<=N;j++) {
			scanf("%d",&a[i][j]);
		}
	}
	int tt=4,x=1;
	if(N<=8) {
		x=N+1;
		tt=0;
	} 
	while(tt--) {
		int aa,b,c,d=0;
		for(int i=x;i<=N&&(d==0);i++) {
			for(int j=x;j<=N;j++) {
			//	printf("%d ",a[i][j]);
				if(tr(i,j,1,1)) {
					aa=i,b=j,c=1,d=1;
					break;
				}
				if(tr(i,j,1,2)) {
					aa=i,b=j,c=1,d=2;
					break;
				}
				if(tr(i,j,2,1)) {
					aa=i,b=j,c=2,d=1;
					break;
				}
			}
		}
		if(d==0) break;
		p[aa]=1;p[aa+c]=2;int qq=2;
		for(int i=x;i<=N;i++) if(i!=aa&&i!=aa+c) {
			qq++;p[i]=qq;
		}
		p2[b]=1;p2[b+d]=2;qq=2;
		for(int i=x;i<=N;i++) if(i!=b&&i!=b+d) {
			qq++;p2[i]=qq;
		}
		for(int i=x;i<=N;i++) for(int j=x;j<=N;j++) a2[p[i]][p2[j]]=a[i][j];
		for(int i=x;i<=N;i++) for(int j=x;j<=N;j++) a[i][j]=a2[i][j];
		x+=2;
	}
	if(x==9&&N>8) {
		printf("YYYYY");
		return 0;
	}
	//printf("%d\n",x);
	x--;
	for(int i=x+2;i<=N;i++) t2[i]=a[x+1][i];
	for(int i=x+2;i<=N;i++) t1[i]=(a[i][x+1]+a[x+1][1+x])%5;
	for(int i=x+2;i<=N;i++) {
		for(int j=x+2;j<=N;j++) {
			assert(a[i][j]==(t1[i]+t2[j])%5);
		}
	}
	dp[N+1][0][0]=1;
	dp2[N+1][0][0]=1;
	for(int i=N;i>=x+1;i--) {
		for(int j=0;j<(1<<x);j++) {
			for(int k=0;k<5;k++) {
				dp2[i][j][(k+t1[i])%5]|=dp2[i+1][j][k];
				dp[i][j][(k+t2[i])%5]|=dp[i+1][j][k];
				for(int l=0;l<x;l++) {
					if((j>>l)&1) {
						dp2[i][j|(1<<l)][(k+a[i][l+1])]|=dp2[i+1][j][k];
						dp2[i][j|(1<<l)][(k+a[l+1][i])]|=dp2[i+1][j][k];
					}
				}
			}
		}
	}
	for(int i=0;i<(1<<x);i++) {
		memset(v2,0,sizeof(v2));
		for(int j=0;j<5;j++) for(int k=0;k<5;k++) {
			if(dp[x+1][i][j]&&dp2[x+1][i][k]) v2[(j+k)%5]=1;
		}
		int kk=0,ll=1;
		for(int j=1;j<=x;j++) {
			if((i>>j-1)%2==0) {
				st[++kk]=j;p[kk]=kk;ll*=kk;
			}
		}
		while(ll--) {
			int as=0;
			for(int z=1;z<=kk;z++) as=(as+a[st[z]][st[p[z]]])%5;
			for(int i=0;i<5;i++) if(v2[i]) vc[(i+as)%5]=1;
			std::next_permutation(p+1,p+kk+1);
		}
	}
	for(int i=0;i<5;i++) if(vc[i]) printf("Y");else printf("N");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10132kb

input:

2
0 4
4 0

output:

YNNYN

result:

ok "YNNYN"

Test #2:

score: 0
Accepted
time: 2ms
memory: 12072kb

input:

2
1 1
1 1

output:

NNYNN

result:

ok "NNYNN"

Test #3:

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

input:

4
0 0 1 0
0 1 0 1
0 0 0 0
1 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #4:

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

input:

4
0 0 0 1
0 1 0 1
1 0 0 0
0 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #5:

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

input:

10
1 4 2 0 0 2 0 1 3 3
0 3 1 4 4 1 4 0 2 2
1 4 2 0 0 2 0 1 0 3
0 3 1 4 4 1 4 0 2 2
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
1 4 2 0 0 2 0 1 3 3
3 1 4 2 2 4 2 3 0 0

output:

NYNNY

result:

ok "NYNNY"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 7892kb

input:

10
4 4 4 1 3 4 1 4 3 0
3 3 3 0 2 3 0 3 2 4
3 3 3 0 2 3 0 3 2 4
4 4 4 1 3 4 1 4 3 0
2 2 2 4 1 2 4 2 1 3
2 2 2 4 1 3 4 2 1 3
4 4 4 1 3 4 1 4 3 0
3 3 3 0 2 3 0 3 2 4
2 2 2 4 1 2 4 2 1 3
4 4 4 1 3 4 1 1 3 0

output:

YYYYY

result:

wrong answer 1st words differ - expected: 'YYYNY', found: 'YYYYY'