QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#426500 | #6325. Peaceful Results | by_chance | WA | 1041ms | 119408kb | C++17 | 2.3kb | 2024-05-31 13:03:06 | 2024-05-31 13:03:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=4e6+5,P=998244353;
inline void pls(int&a,int b){a+=b;if(a>=P)a-=P;}
int qpow(int a,int b=P-2){
int c=1;
for(;b;b>>=1,a=1ll*a*a%P)
if(b&1)c=1ll*c*a%P;
return c;
}
int n,fac[N],ifac[N],inv[N];
int a[15],b[15],flag;
int f[N],g[N],h[N],rev[N],_G[N],invG[N];
int ask(int i){if(i>=0&&i<N)return ifac[i];else return 0;}
void NTT(int*f,int n,int op){
for(int i=0;i<n;++i)if(i<rev[i])swap(f[i],f[rev[i]]);
for(int p=2;p<=n;p<<=1){
int len=p>>1,tG=(op==1?_G[p]:invG[p]);
for(int k=0;k<n;k+=p){
int buf=1;
for(int l=k;l<k+len;++l){
int tmp=1ll*f[l+len]*buf%P;f[l+len]=f[l];
pls(f[l+len],P-tmp);pls(f[l],tmp);buf=1ll*buf*tG%P;
}
}
}
if(op==-1){
for(int i=0;i<n;++i)
f[i]=1ll*f[i]*inv[n]%P;
}
}
void times(int*f,int*g,int m){
int n=1;for(;n<=2*m;n<<=1);for(int i=m;i<n;++i)f[i]=g[i]=0;
for(int i=0;i<n;++i)rev[i]=(rev[i>>1]>>1)|((i&1)?(n>>1):0);
NTT(f,n,1);NTT(g,n,1);for(int i=0;i<n;++i)f[i]=1ll*f[i]*g[i]%P;
NTT(f,n,-1);for(int i=m;i<n;++i)f[i]=0;
}
void init(){
fac[0]=ifac[0]=inv[1]=1;
for(int i=1;i<N;++i)fac[i]=1ll*fac[i-1]*i%P;
for(int i=2;i<N;++i)inv[i]=1ll*(P-P/i)*inv[P%i]%P;
for(int i=1;i<N;++i)ifac[i]=1ll*ifac[i-1]*inv[i]%P;
for(int i=1;i<N;i<<=1)_G[i]=qpow(3,(P-1)/i),invG[i]=qpow((P+1)/3,(P-1)/i);
}
int main(){
init();scanf("%d",&n);flag=1;
for(int i=1;i<=9;++i)scanf("%d",a+i);
b[1]=-a[1]-2*a[2]+2*a[4]+a[5]+2*a[7]+a[8];
b[2]=-2*a[1]-a[2]+a[4]+2*a[5]+a[7]+2*a[8];b[3]=a[3];
b[4]=2*a[1]+a[2]-a[4]+a[5]-a[7]-2*a[8];
b[5]=2*a[1]+a[2]-a[4]-2*a[5]-a[7]+a[8];
b[6]=a[1]+2*a[2]+a[4]-a[5]-2*a[7]-a[8];
b[7]=a[1]+2*a[2]-2*a[4]-a[5]+a[7]-a[8];
for(int i:{1,2,4,5,6,7}){if(b[i]%3==0)b[i]/=3;else flag=0;}
if(!flag){printf("0\n");return 0;}
for(int i=0;i<=n;++i){
f[i]=1ll*ask(b[1]-n+i)*ask(b[2]-n+i)%P*ask(b[3]-n+i)%P;
g[i]=1ll*ask(b[4]+i)*ask(b[7]+i)%P*ask(b[9]+i)%P;
h[i]=1ll*ask(b[5]+i)*ask(b[6]+i)%P*ask(b[8]+i)%P;
}
times(f,g,n+1);int ans=0;
for(int i=0;i<=n;i++)ans=(ans+1ll*f[i]*h[n-i]%P)%P;
printf("%lld\n",1ll*fac[n]*ans%P);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 49ms
memory: 71492kb
input:
2 2 0 0 1 1 0 1 0 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 46ms
memory: 65712kb
input:
3 0 1 2 3 0 0 1 1 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 254ms
memory: 86696kb
input:
333333 111111 111111 111111 111111 111111 111111 111111 111111 111111
output:
383902959
result:
ok 1 number(s): "383902959"
Test #4:
score: -100
Wrong Answer
time: 1041ms
memory: 119408kb
input:
1500000 500000 500000 500000 500000 500000 500000 500000 500000 500000
output:
479967071
result:
wrong answer 1st numbers differ - expected: '355543262', found: '479967071'