QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#218139 | #6325. Peaceful Results | Mu_Silk | RE | 409ms | 78736kb | C++17 | 2.7kb | 2023-10-17 19:05:41 | 2023-10-17 19:05:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> poly;
const ll M=998244353;
ll qpow(ll a,ll b){
a%=M;
ll ans=1;
while(b){
if(b&1)ans=ans*a%M;
a=a*a%M;
b>>=1;
}
return ans;
}
const ll g=3,rg=qpow(g,M-2);
vector<int>rev;
void NTT(poly& f,int op){
for(int i=0;i<f.size();i++)if(i<rev[i])swap(f[i],f[rev[i]]);
for(int m=1;m<f.size();m<<=1){
ll gn=qpow(op==1?g:rg,(M-1)/(m<<1));
for(int j=0;j<f.size();j+=(m<<1)){
ll w=1;
for(int k=0;k<m;k++,w=w*gn%M){
ll x=f[j+k],y=w*f[j+k+m]%M;
f[j+k]=(x+y)%M;
f[j+k+m]=(x-y+M)%M;
}
}
}
if(op==-1){
ll inv=qpow(f.size(),M-2);
for(int i=0;i<f.size();i++)f[i]=f[i]*inv%M;
}
}
//多项式乘法,nlog(n):NTT;
poly operator*(poly f,poly g){
int len=f.size()+g.size()-1;
int c=0;for(int t=1;t<len;t<<=1)c++;
int deg=(1<<c);rev.resize(deg);rev[0]=0;
for(int i=1;i<deg;i++)rev[i]=(rev[i>>1]>>1)+((i&1)<<(c-1));
f.resize(deg);g.resize(deg);NTT(f,1);NTT(g,1);
for(int i=0;i<deg;i++)f[i]=f[i]*g[i]%M;
NTT(f,-1);f.resize(len);
return f;
}
const ll N=2000010;
ll p[N],rp[N];
void init(){
p[0]=1;
for(int i=1;i<N;i++)p[i]=p[i-1]*i%M;
rp[N-1]=qpow(p[N-1],M-2);
for(int i=N-2;i>=0;i--)rp[i]=rp[i+1]*(i+1)%M;
}
void solve(){
init();
int n;cin>>n;
ll A[10],Y[10];
for(int i=1;i<=9;i++){
cin>>A[i];
}
ll tmp;
tmp=-A[1]+A[2]-A[4]+A[5]-A[7]+A[8];
if(tmp%3==0)Y[1]=tmp/3;
else {cout<<"0\n";return;}
tmp=-A[1]+A[3]-A[4]+A[6]-A[7]+A[9];
if(tmp%3==0)Y[2]=tmp/3;
else {cout<<"0\n";return;}
tmp=-2*A[1]-A[3]+A[4]+2*A[6]+A[7]-A[9];
if(tmp%3==0)Y[3]=tmp/3;
else {cout<<"0\n";return;}
tmp=-2*A[1]-A[2]+A[4]-A[5]+A[7]+2*A[8];
if(tmp%3==0)Y[4]=tmp/3;
else {cout<<"0\n";return;}
tmp=-2*A[1]-A[2]+A[4]+2*A[5]+A[7]-A[8];
if(tmp%3==0)Y[5]=tmp/3;
else {cout<<"0\n";return;}
tmp=-2*A[1]-A[3]+A[4]-A[6]+A[7]+2*A[9];
if(tmp%3==0)Y[6]=tmp/3;
else {cout<<"0\n";return;}
poly a(A[1]+1),b(A[1]+1),c(A[1]+1);
for(int i=-min(Y[1],Y[2]);i<=A[1];i++){
a[i]=rp[i]*rp[i+Y[1]]%M*rp[i+Y[2]]%M;
}
for(int i=-min(Y[3],Y[4]);i<=A[1];i++){
b[i]=rp[i]*rp[i+Y[3]]%M*rp[i+Y[4]]%M;
}
for(int i=-min(Y[5],Y[6]);i<=A[1];i++){
c[i]=rp[i]*rp[i+Y[5]]%M*rp[i+Y[6]]%M;
}
//cout<<p[n]<<"\n";
a=a*b;a.resize(A[1]+1);
a=a*c;cout<<a[A[1]]*p[n]%M<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n=1;
//cin>>n;
while(n--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 21ms
memory: 34864kb
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: 16ms
memory: 35092kb
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: 99ms
memory: 45092kb
input:
333333 111111 111111 111111 111111 111111 111111 111111 111111 111111
output:
383902959
result:
ok 1 number(s): "383902959"
Test #4:
score: 0
Accepted
time: 409ms
memory: 78660kb
input:
1500000 500000 500000 500000 500000 500000 500000 500000 500000 500000
output:
355543262
result:
ok 1 number(s): "355543262"
Test #5:
score: 0
Accepted
time: 405ms
memory: 78736kb
input:
1499999 499999 499999 500001 499999 499999 500001 499999 499999 500001
output:
934301164
result:
ok 1 number(s): "934301164"
Test #6:
score: 0
Accepted
time: 21ms
memory: 34816kb
input:
1500000 1 0 1499999 1499999 1 0 0 1499999 1
output:
1500000
result:
ok 1 number(s): "1500000"
Test #7:
score: -100
Runtime Error
input:
1499999 0 749999 750000 750000 0 749999 749999 750000 0