QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#861627 | #8830. Breaking Bad | DaiRuiChen007 | WA | 1ms | 9084kb | C++17 | 2.2kb | 2025-01-18 18:50:29 | 2025-01-18 18:50:29 |
Judging History
answer
#include<bits/stdc++.h>
#define pc __builtin_popcount
using namespace std;
const int MAXN=1005;
int n,a[MAXN][MAXN],tmp[MAXN][MAXN],tf[MAXN],tg[MAXN];
int mod(int s) { return (s>>5)|(s&31); }
int mul(int s,int t) {
int z=0;
for(int i:{0,1,2,3,4}) if(t>>i&1) z|=mod(s<<i);
return z;
}
int dp[1<<8][1<<8],f[1<<8],g[1<<8],h[1<<8];
signed main() {
scanf("%d",&n);
for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) scanf("%d",&a[i][j]);
int p=0;
while(p<5&&2*p<=n-2) {
int xf=0,xg=0;
for(int i=1;i<=n;++i) {
if(!tf[i]) xf=i;
if(!tg[i]) xg=i;
}
for(int i=1;i<=n;++i) if(!tf[i]&&i!=xf){
for(int j=1;j<=n;++j) if(!tg[j]&&j!=xg) {
if((a[xf][xg]+a[i][j])%5!=(a[xf][j]+a[i][xg])%5) {
tf[i]=2*p+1,tf[xf]=2*p+2;
tg[j]=2*p+1,tg[xg]=2*p+2;
goto fl;
}
}
}
break; fl:++p;
}
if(p==5) return puts("YYYYY"),0;
for(int i=1,cf=2*p,cg=2*p;i<=n;++i) {
if(!tf[i]) tf[i]=++cf;
if(!tg[i]) tg[i]=++cg;
}
for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) tmp[tf[i]-1][tg[j]-1]=a[i][j];
memcpy(a,tmp,sizeof(a));
// cerr<<"p = "<<p<<"\n";
int u=2*p,dis=0;
for(int i=u;i<n;++i) {
int x=(5-a[i][u])%5; dis=(dis+5-x)%5;
for(int j=0;j<n;++j) a[i][j]=(a[i][j]+x)%5;
}
for(int j=u;j<n;++j) {
int x=(5-a[u][j])%5; dis=(dis+5-x)%5;
for(int i=0;i<n;++i) a[i][j]=(a[i][j]+x)%5;
}
// cerr<<"dis = "<<dis<<"\n";
int rs=0,U=1<<(2*p);
f[0]=g[0]=1;
for(int i=2*p;i<n;++i) {
memcpy(h,f,sizeof(h));
for(int s=0;s<U;++s) if(f[s]) {
for(int j=0;j<2*p;++j) if(!(s>>j&1)) {
f[s|1<<j]|=mod(f[s]<<a[j][i]);
}
}
memcpy(f,h,sizeof(h));
memcpy(h,g,sizeof(h));
for(int s=0;s<U;++s) if(g[s]) {
for(int j=0;j<2*p;++j) if(!(s>>j&1)) {
g[s|1<<j]|=mod(g[s]<<a[i][j]);
}
}
memcpy(g,h,sizeof(h));
}
dp[0][0]=1;
for(int s=0;s<U;++s) for(int t=0;t<U;++t) if(dp[s][t]) {
rs|=mul(dp[s][t],mul(f[(U-1)^s],g[(U-1)^t]));
// cerr<<"dp["<<s<<","<<t<<"] = "<<dp[s][t]<<" * "<<f[U-1-s]<<" * "<<g[U-1-t]<<"\n";
for(int i=0;i<2*p;++i) if(!(s>>i&1)) for(int j=0;j<2*p;++j) if(!(t>>j&1)) {
dp[s|1<<i][t|1<<j]|=mod(dp[s][t]<<a[i][j]);
}
}
// cerr<<"RS = "<<rs<<"\n";
rs=mod(rs<<dis);
for(int i=0;i<5;++i) cout<<"NY"[rs>>i&1];
cout<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7892kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 0ms
memory: 8412kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 1ms
memory: 8676kb
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: 8424kb
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: 0ms
memory: 8656kb
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: 0
Accepted
time: 1ms
memory: 8448kb
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:
YYYNY
result:
ok "YYYNY"
Test #7:
score: 0
Accepted
time: 0ms
memory: 8320kb
input:
10 1 2 0 4 2 3 4 0 2 3 0 1 4 3 1 2 3 4 1 2 4 0 3 2 0 1 2 3 0 1 1 2 0 4 2 3 4 0 2 3 3 4 2 1 4 0 1 2 4 0 0 1 4 3 1 2 3 4 1 2 2 3 1 0 3 4 0 1 3 4 3 1 1 1 4 0 1 2 4 0 1 2 0 4 2 3 4 0 2 3 1 3 0 4 2 3 4 0 2 3
output:
NYYYY
result:
ok "NYYYY"
Test #8:
score: 0
Accepted
time: 0ms
memory: 8832kb
input:
10 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4 2 3 4 2 1 1 4 3 4 1 0 1 2 0 4 4 2 1 2 4 0 1 2 0 4 4 2 1 2 4 0 1 2 0 4 4 2 1 2 4 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4
output:
NYNNN
result:
ok "NYNNN"
Test #9:
score: -100
Wrong Answer
time: 0ms
memory: 9084kb
input:
10 4 1 3 1 2 0 3 2 4 4 0 2 4 2 3 1 4 3 0 0 1 1 1 1 2 0 3 2 4 1 2 4 1 4 0 3 1 0 2 2 1 3 0 3 4 2 0 4 1 1 2 4 1 4 0 3 1 0 2 2 2 4 1 4 0 3 1 0 2 2 0 2 4 2 3 1 4 3 0 0 3 0 2 1 1 4 2 1 3 3 4 1 3 1 2 0 3 2 4 4
output:
NYYYY
result:
wrong answer 1st words differ - expected: 'YYYYY', found: 'NYYYY'