QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#459743 | #8830. Breaking Bad | Crysfly | WA | 1ms | 7660kb | C++17 | 4.7kb | 2024-06-30 12:51:04 | 2024-06-30 12:51:05 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 2013265921
struct modint{
unsigned int x;
modint(unsigned int o=0){x=o;}
modint &operator = (unsigned int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x<o.x?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(unsigned int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,unsigned int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,unsigned int y){return x^y;}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 2000005
#define inf 0x3f3f3f3f
int n,a[1005][1005],sum,k,res[6],b[1005][1005];
int p1[1005],i1[1005],i2[1005],m;
bool f[1<<6][6],tf[1<<6][6],g[1<<6][6],h[1<<6][1<<6][6];
void work()
{
n=read();
For(i,1,n)For(j,1,n)a[i][j]=read();
For(_,1,4){
if(a[1][1]){
int t=a[1][1];
sum=(sum+a[1][1]*n)%5;
For(i,1,n)For(j,1,n)a[i][j]=(a[i][j]-t+5)%5;
}
For(i,2,n-k){
int t=(a[1][i]-a[1][1]+5)%5;
sum=(sum+t)%5;
For(j,1,n) a[j][i]=(a[j][i]-t+5)%5;
}
For(i,2,n-k){
int t=(a[i][1]-a[1][1]+5)%5;
sum=(sum+t)%5;
For(j,1,n) a[i][j]=(a[i][j]-t+5)%5;
}
bool ok=0;
int pi=0,pj=0;
For(i,2,n-k) For(j,2,n-k) if(!ok && a[i][j]) {
ok=1; pi=i; pj=j;
break;
}
if(!ok) break;
if(_==4){
puts("YYYYY");
exit(0);
}
// cout<<"find "<<pi<<" "<<pj<<"\n";
For(i,1,n-k) {
int ti=(i-1-(i>=pi));
if(i==1)ti=n-k-1;
if(i==pi)ti=n-k;
For(j,1,n-k){
int tj=(j-1-(j>=pj));
if(j==1)tj=n-k-1;
if(j==pj)tj=n-k;
b[ti][tj]=a[i][j];
}
}
For(i,1,n-k) For(j,1,n-k) a[i][j]=b[i][j];
k+=2;
}
// cout<<"sum "<<sum<<"\n";
// For(i,1,n)For(j,1,n)cout<<a[i][j]<<" \n"[j==n];
For(i,n-k+1,n) p1[++m]=i;
f[0][0]=1;
For(i,1,n-k){
// cout<<"A: ";For(j,0,k-1)cout<<a[i][p1[j+1]]<<" "; cout<<"\n";
For(s,0,(1<<k)-1)For(rs,0,4)if(f[s][rs]){
For(j,0,k-1)if(!(s>>j&1))
tf[s|(1<<j)][(rs+a[i][p1[j+1]])%5]=1;
}
For(s,0,(1<<k)-1)For(rs,0,4)f[s][rs]|=tf[s][rs],tf[s][rs]=0;
}
g[0][0]=1;
For(i,1,n-k){
// cout<<"a: ";For(j,0,k-1)cout<<a[p1[j+1]][i]<<" "; cout<<"\n";
For(s,0,(1<<k)-1)For(rs,0,4)if(g[s][rs]){
For(j,0,k-1)if(!(s>>j&1))
tf[s|(1<<j)][(rs+a[p1[j+1]][i])%5]=1;
}
For(s,0,(1<<k)-1)For(rs,0,4)g[s][rs]|=tf[s][rs],tf[s][rs]=0;
}
int all=((1<<k)-1);
h[0][0][0]=1;
// For(i,0,k-1)For(j,0,k-1)cout<<a[p1[i+1]][p1[j+1]]<<" \n"[j==k-1];
For(i,0,k-1){
For(s,0,(1<<i)-1)For(t,0,(1<<k)-1)For(rs,0,4){
if(h[s][t][rs]){
For(j,0,k-1) if(!(t>>j&1)){
h[s|(1<<i)][t|(1<<j)][(rs+a[p1[j+1]][p1[i+1]])%5]=1;
}
}
}
}
// For(rs,0,4)cout<<h[all^8^4][all^1^4][rs]<<" ";cout<<"\n";
For(s1,0,(1<<k)-1) For(s2,0,(1<<k)-1) {
For(r1,0,4) if(f[s1][r1]) For(r2,0,4) if(g[s2][r2])
For(r3,0,4) if(h[all^s1][all^s2][r3]){
// if(__builtin_popcount(s1) != __builtin_popcount(s2))puts("???");
// if((r1+r2+r3+sum)%5==3) cout<<"s1 "<<s1<<" "<<r1<<" "<<s2<<" "<<r2<<" "<<r3<<"\n";
res[(r1+r2+r3)%5]=1;
}
}
For(i,0,4) if(res[((i-sum+5)%5)]) cout<<'Y'; else cout<<'N';
}
signed main()
{
// freopen("data.in","r",stdin);
int T=1;
while(T--)work();
return 0;
}
/*
10
4 2 2 2 0 0 1 1 3 3
1 4 0 4 2 2 3 3 0 0
2 0 1 0 3 3 4 4 1 1
2 0 1 0 3 3 4 4 1 1
2 0 1 0 3 3 4 4 1 1
4 2 3 2 0 0 1 1 3 3
3 1 2 1 4 4 0 0 2 2
3 1 2 1 4 4 0 3 2 2
1 4 0 4 2 2 3 3 0 0
1 4 0 4 2 2 3 3 0 0
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5728kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5804kb
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: 7660kb
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: 5644kb
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: 0ms
memory: 5836kb
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: 1ms
memory: 5700kb
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: 1ms
memory: 5720kb
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: 0
Accepted
time: 0ms
memory: 5824kb
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:
YYYYY
result:
ok "YYYYY"
Test #10:
score: 0
Accepted
time: 0ms
memory: 5660kb
input:
10 1 2 0 2 4 2 3 1 2 1 4 0 3 0 2 0 1 4 0 4 0 1 4 1 3 1 2 0 1 0 0 1 4 1 3 1 2 0 1 0 3 4 2 4 1 4 0 3 4 3 4 0 3 0 2 0 1 4 0 4 0 1 4 1 3 1 2 0 1 0 0 1 4 1 3 1 2 0 1 0 3 4 2 4 1 4 0 3 4 3 0 1 4 1 3 1 2 0 1 0
output:
NNNYN
result:
ok "NNNYN"
Test #11:
score: 0
Accepted
time: 0ms
memory: 5768kb
input:
10 1 4 1 2 1 3 3 2 1 2 0 3 0 1 0 2 2 1 0 1 0 4 0 3 0 2 2 1 0 1 1 4 1 2 1 3 3 2 1 2 4 2 4 0 4 1 1 0 4 0 1 1 1 4 1 0 3 2 1 2 0 0 0 1 0 2 2 1 0 1 2 0 2 3 2 4 4 3 2 3 2 0 2 3 2 4 4 3 2 3 2 0 2 3 2 4 4 3 2 3
output:
YYYYY
result:
ok "YYYYY"
Test #12:
score: 0
Accepted
time: 1ms
memory: 5820kb
input:
10 1 2 0 1 4 0 1 2 2 2 1 2 0 1 4 3 1 2 2 2 0 1 4 0 3 1 0 1 1 1 1 2 0 1 4 3 1 2 2 2 3 4 2 3 1 4 3 4 4 4 0 1 4 0 3 1 0 1 1 1 4 0 3 4 2 0 4 0 0 0 3 4 2 3 1 4 3 4 4 4 4 0 3 4 2 0 4 0 0 0 0 1 4 0 3 1 0 1 1 1
output:
YNYNY
result:
ok "YNYNY"
Test #13:
score: -100
Wrong Answer
time: 0ms
memory: 5768kb
input:
10 1 3 0 0 2 1 3 4 3 3 3 3 0 0 4 1 3 4 3 3 1 1 3 3 2 4 1 2 1 1 2 4 1 1 3 2 4 0 4 4 4 1 3 3 0 4 1 2 1 1 2 4 1 1 3 2 4 0 4 4 0 2 4 4 1 0 2 3 2 2 3 0 2 2 4 3 0 1 0 0 3 0 2 2 4 3 0 1 0 0 4 2 4 4 1 0 2 3 2 2
output:
YYYYY
result:
wrong answer 1st words differ - expected: 'YYYNY', found: 'YYYYY'