QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471369#8830. Breaking Baducup-team3519#WA 15ms5772kbC++202.6kb2024-07-10 20:45:532024-07-10 20:45:53

Judging History

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

  • [2024-07-10 20:45:53]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:5772kb
  • [2024-07-10 20:45:53]
  • 提交

answer

#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
#define ll long long
const int N=1005;
const ll mod=998244353;
ll qpow(ll a,ll b){
	ll ans=1;
	if(b==0)
	return 1;
	if(b%2)
	ans=a;
	ll t=qpow(a,b/2);
	return t*t%mod*ans%mod;
}
ll inv(ll a){
	return qpow(a,mod-2);
}
ll ans[5];
ll n;
ll a[N][N];
ll b[N][N];
void nb(){
	for(int i=0;i<=4;i++){
		ans[i]=1;
	}
}
int ext=0;
void flipacc(int x,int y){
	vector<int>fx(n+1),fy(n+1);
	for(int i=1;i<=n;i++){
		fy[i]=(5-a[x][i])%5;
		
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
		a[i][j]=(a[i][j]+fy[j])%5;
	}
	for(int i=1;i<=n;i++){
		fx[i]=(5-a[i][y])%5;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			a[i][j]=(a[i][j]+fx[i])%5;
		}
	}
//	
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=n;j++){
//			//a[x][j]=a[x][j]+fx[x]+fy[j]=0;
//			//a[j][y]=a[j][y]+fx[j]+fy[y]
//			a[i][j]=(a[i][j]+fx[i]+fy[j])%5;
//		}
//	}
	for(int i=1;i<=n;i++){
		ext+=fx[i]+fy[i];
	}
	ext%=5;
//	cout<<x<<' '<<y<<' '<<'\n';
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=n;j++){
//			cout<<a[i][j]<<' ';
//		}
//		cout<<'\n';
//	}
}
void calc(int k){
	vector<int>p;
	for(int i=1;i<=k;i++){
		p.push_back(i);
	}
//	for(int i=1;i<=k;i++){
//		for(int j=1;j<=k;j++){
//			cout<<b[i][j]<<' ';
//			cout<<'\n';		}
//	}
	do{
		int cur=ext;
		for(int i=1;i<=k;i++){
			cur+=b[i][p[i-1]];
		}	
		//cout<<cur<<'\n';
		cur%=5;
		ans[cur]=1;
	}
	while(next_permutation(p.begin(),p.end()));
	
}
void checkgrid(){
	vector<int>sx,sy;
	for(int i=1;i<=n;i++){
		int cnt=0;
		for(int j=1;j<=n;j++){
			cnt+=a[i][j];
		}
		if(cnt!=0){
			sx.push_back(i);
		}
	}
	for(int i=1;i<=n;i++){
		int cnt=0;
		for(int j=1;j<=n;j++){
			cnt+=a[j][i];
		}
		if(cnt!=0){
			sy.push_back(i);
		}
	}
	if(sx.size()>=9||sy.size()>=9){
		nb();
	}
	else{
		for(int i=1;i<=8;i++){
			for(int j=1;j<=8;j++){
				b[i][j]=0;
			}
		}
		for(int i=0;i<sx.size();i++){
			for(int j=0;j<sy.size();j++){
				b[i+1][j+1]=a[sx[i]][sy[j]];
			}
		}
		calc(8);
	}
}

void solve(){
	cin>>n;
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
		}
	}
	if(n<=8){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				b[i][j]=a[i][j];
			}
		}
		calc(n);
	}
	else{
		for(int i=1;i<=8;i++){
			for(int j=1;j<=8;j++){
				flipacc(i,j);
				checkgrid();
			}
		}
	}
	for(int i=0;i<=4;i++){
		if(ans[i])cout<<'Y';
		else cout<<'N';
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
0 4
4 0

output:

YNNYN

result:

ok "YNNYN"

Test #2:

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

input:

2
1 1
1 1

output:

NNYNN

result:

ok "NNYNN"

Test #3:

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

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: 1ms
memory: 5688kb

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: -100
Wrong Answer
time: 15ms
memory: 5772kb

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:

YYYYY

result:

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