QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#458256 | #8830. Breaking Bad | ucup-team1004# | WA | 1ms | 3848kb | C++14 | 1.4kb | 2024-06-29 16:27:32 | 2024-06-29 16:27:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10,B=15;
int p1[N],p2[N],d1[N],d2[N],a[N][N],n,f[1<<B];
int R(int x){return (x|(x>>5))&31;}
bool solve(int A,int B)
{
int sum=A+B;
for(int i=1;i<n;i++)
{
p1[i]=p2[i]=0;
d1[i]=(a[i][0]-B+5)%5;
d2[i]=(a[0][i]-A+5)%5;
sum+=d1[i]+d2[i];
}
sum=5-sum%5;
for(int i=1;i<n;i++)
for(int j=1;j<n;j++)
if((d1[i]+d2[j])%5!=a[i][j]) p1[i]=p2[j]=1;
vector<int> v1,v2;
for(int i=1;i<n;i++)
{
if(p1[i]) v1.push_back(i);
if(p2[i]) v2.push_back(i);
}
int m=min(v1.size(),v2.size());
if(m>B) return 0;
if((int)v2.size()==m)
{
swap(v1,v2);
for(int i=1;i<n;i++)
for(int j=1;j<i;j++) swap(a[i][j],a[j][i]);
}
for(int i=0;i<(1<<m);i++)
if(__builtin_popcount(i)<=1) f[i]=1;
for(int i=1;i<n;i++)
for(int j=(1<<m)-1;j>=0;j--)
for(int k=0;k<m;k++)
if(!(j>>k&1))
{
int w=(a[v1[k]][i]+10-d1[v1[k]]-d2[i])%5;
f[j|(1<<k)]|=R(f[j]<<w);
}
for(int i=0;i<5;i++) putchar("NY"[f[(1<<m)-1]>>((i+sum)%5)&1]);
return 1;
}
mt19937 rnd(114514);
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%d",&a[i][j]);
while(1.*clock()/CLOCKS_PER_SEC<0.99)
{
int x=rnd()%n,y=rnd()%n;
for(int i=0;i<n;i++) swap(a[0][i],a[x][i]);
for(int i=0;i<n;i++) swap(a[i][0],a[i][y]);
for(int i=0;i<5;i++)
if(solve(i,(a[0][0]-i+5)%5)) return 0;
}
puts("YYYYY");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3648kb
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: 3728kb
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: 1ms
memory: 3688kb
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:
YYYNY
result:
wrong answer 1st words differ - expected: 'NYNNY', found: 'YYYNY'