QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#459578 | #8830. Breaking Bad | ucup-team1231# | TL | 1ms | 7928kb | C++14 | 2.8kb | 2024-06-30 08:45:04 | 2024-06-30 08:45:07 |
Judging History
answer
#pragma GCC optimize("-Ofast","-funroll-all-loops","-ffast-math")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SZ 666666
#define pb push_back
#define fi first
#define se second
#define mp make_pair
const int MOD=969999931;
const int omega=18844598;
int n,a[1005][1005],w[1005][1005];
ll v[1005][1005];
ll qp(ll a,ll b) {
ll x=1; a%=MOD;
while(b) {
if(b&1) x=x*a%MOD;
a=a*a%MOD; b>>=1;
}
return x;
}
ll ev(ll s) {
// cerr<<"+\n";
// calc det mod (x-s)
for(int i=0;i<n;++i)
for(int j=0;j<n;++j) {
ll x=1;
for(int ss=a[i][j];ss;--ss)
x=x*s%MOD;
v[i][j]=x*w[i][j]%MOD;
}
// cerr<<"+AA\n";
ll r=1;
for(int i=0;i<n;++i) {
int j=i;
while(j<n&&v[j][i]%MOD==0) ++j;
if(j>=n) return 0;
if(i!=j) {
r=-r;
for(int s=0;s<n;++s)
swap(v[i][s],v[j][s]);
}
for(int s=0;s<n;++s) v[i][s]%=MOD;
r=r*v[i][i]%MOD;
if(r==0) return 0;
ll iv=qp(v[i][i],MOD-2);
for(int j=i+1;j<n;++j) {
int vv=v[j][i]%MOD*iv%MOD;
if(vv)
for(int k=i+1;k<n;++k) {
v[j][k]=(v[j][k]-(ll)vv*v[i][k]);
}
if(i%8==0) {
for(int k=i+1;k<n;++k) v[j][k]%=MOD;
}
}
}
// cerr<<"+SS\n";
return (r%MOD+MOD)%MOD;
}
ll ss[5];
ll PP[66],FF[66],QQ[66];
ll eval(ll*a,ll v) {
ll x=0;
for(int i=5;i>=0;--i)
x=(x*v+a[i])%MOD;
return x;
}
int main() {
cin>>n;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j) {
cin>>a[i][j];
w[i][j]=rand()%MOD;
}
PP[0]=1;
ll o=1;
for(int i=0;i<5;++i) {
ss[i]=ev(o);
ll Fe=eval(FF,o),Pe=eval(PP,o);
ll sth=(ss[i]-Fe)*qp(Pe,MOD-2)%MOD;
// cerr<<Fe<<"++"<<Pe<<"what"<<sth<<"++\n";
// FF += PP * sth, PP *= x-o
for(int j=0;j<=5;++j)
FF[j]=(FF[j]+PP[j]*sth)%MOD;
for(int j=0;j<=5;++j)
QQ[j]=PP[j]*(-o)%MOD;
for(int j=0;j<=5;++j)
(QQ[j+1]+=PP[j])%=MOD;
for(int j=0;j<=5;++j) PP[j]=QQ[j];
o=o*omega%MOD;
// cout<<ss[i]<<"++\n";
// for(int j=0;j<=5;++j)
// cout<<FF[j]<<",";
// cout<<"fff\n";
// for(int j=0;j<=5;++j)
// cout<<QQ[j]<<",";
// cout<<"xxx\n";
}
for(int j=0;j<5;++j) printf("%c",(FF[j]%MOD)?'Y':'N');
printf("\n");
}
/*
x^{a[i][j]}
x^5-1=(x-1)(x-o)(x-o^2)(x-o^3)(x-o^4)
FFF mod P
?? mod (x-o)
FFF+something*P == ss[...] so that it equals to 0 when x=o
0 mod 1
xxx mod (x-o)
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7900kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7832kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7848kb
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: 7808kb
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: 1ms
memory: 7876kb
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: 7928kb
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: 7880kb
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: 7884kb
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: 7868kb
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: 7928kb
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: 7856kb
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: 7920kb
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: 0
Accepted
time: 1ms
memory: 7800kb
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:
YYYNY
result:
ok "YYYNY"
Test #14:
score: 0
Accepted
time: 1ms
memory: 7928kb
input:
10 2 0 3 1 3 0 0 0 4 1 1 4 2 0 2 4 4 4 3 0 2 0 3 1 3 0 0 0 4 1 1 4 2 0 2 4 4 4 3 0 1 4 2 0 2 4 4 4 3 0 3 3 4 2 4 1 1 1 0 2 3 1 4 2 4 1 1 1 0 2 4 2 0 3 0 2 2 2 1 3 3 1 4 2 4 1 1 1 0 2 1 4 2 0 2 4 4 4 3 0
output:
YNYNN
result:
ok "YNYNN"
Test #15:
score: -100
Time Limit Exceeded
input:
1000 3 4 1 2 4 1 0 3 0 4 1 4 3 1 4 4 1 0 1 2 3 1 0 1 3 4 4 0 3 0 3 2 2 1 0 4 1 3 3 0 3 1 3 2 2 0 3 3 2 2 3 0 4 2 1 2 1 2 1 4 2 4 1 4 2 4 3 2 0 3 0 4 2 1 2 3 3 0 2 0 3 3 1 1 0 3 4 3 2 0 4 0 3 4 4 2 3 4 2 3 4 2 1 3 2 2 4 1 0 2 2 4 0 1 2 0 4 1 3 2 3 2 2 2 1 4 4 4 2 0 0 4 4 1 3 4 0 2 2 3 1 1 3 2 3 2 3 0...
output:
NNNYN