QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#459842 | #8830. Breaking Bad | lgvc | RE | 2ms | 9900kb | C++14 | 2.3kb | 2024-06-30 14:38:57 | 2024-06-30 14:38:57 |
Judging History
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];
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;
if((a[aa][c]+a[b][d]-a[aa][d]-a[b][c])%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++) {
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;
}
x--;
for(int i=x+1;i<=N;i++) {
for(int j=x+1;j<=N;j++) {
if(i!=x+1) assert(a[i][j]==a[i-1][j]);
if(j!=x+1) assert(a[i][j]==a[i][j-1]);
}
}
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]|=dp2[i+1][j][k];
dp[i][j][k]|=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: 0ms
memory: 9828kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 2ms
memory: 9900kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 2ms
memory: 9864kb
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: 9900kb
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
Runtime Error
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