QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#210097 | #6325. Peaceful Results | ucup-team870 | RE | 382ms | 80740kb | C++17 | 3.7kb | 2023-10-11 01:27:48 | 2023-10-11 01:27:48 |
Judging History
answer
// 0.333333 -0.333333 -0.666667 -0.333333 -0.666667 -0.333333 1 -1 -1
// 0 0 0 0 -1 -1 1 -1 -1
// -0.333333 0.333333 -0.333333 -0.666667 0.666667 0.333333 -0 1 -0
// -0.666667 -0.333333 0.333333 -0.333333 0.333333 0.666667 0 1 0
// -0.333333 -0.666667 -0.333333 0.333333 -0.333333 -0.666667 1 -1 -1
// 0.666667 0.333333 0.666667 0.333333 0.666667 0.333333 -1 -0 1
// 0.333333 0.666667 0.333333 0.666667 0.333333 0.666667 -1 -0 1
#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define P pair<int,int>
#define ll long long
#define vi vector<int>
int K[7][7]={{1,-1,-2,-1,-2,-1,3},{0,0,0,0,-3,-3,3},{-1,1,-1,-2,2,1,0},{-2,-1,1,-1,1,2,0},
{-1,-2,-1,1,-1,-2,3},{2,1,2,1,2,1,-3},{1,2,1,2,1,2,-3} };
int p[7]={-1,-1,0,0,-1,1,1};
const int N=4e6+6,mod=998244353;
ll qp(ll x,ll y){
ll res=1;
while(y){
if(y&1)res=res*x%mod;
x=x*x%mod; y>>=1;
} return res;
}
#define poly vi
const int G=3,Gi=qp(G,mod-2);
int limit=1,L=0; int r[N*4];
void NTT(poly& A,int type){
A.resize(limit);
for(int i=0;i<limit;++i)if(i<r[i])swap(A[i],A[r[i]]);
for(int mid=1;mid<limit;mid<<=1){
ll wn=qp(type==1 ? G:Gi, (mod-1)/(mid<<1));
for(int j=0;j<limit;j+=(mid<<1)){
ll w=1;
for(int k=0;k<mid;k++,w=(w*wn)%mod){
int x=A[j+k],y=w*A[j+k+mid]%mod;
A[j+k]=(x+y)%mod, A[j+k+mid]=(x-y+mod)%mod;
}
}
}
}
void poly_mul_init(poly&a, poly&b){
limit=1; L=0;
int N=a.size()-1,M=b.size()-1;
while(limit<=N+M)limit<<=1,++L;
for(int i=0;i<limit;i++)r[i]=(r[i>>1]>>1|((i&1)<<(L-1)));
}
poly poly_mul(poly a,poly b){
int n=a.size()+b.size()-1;
poly_mul_init(a,b);
NTT(a,1); NTT(b,1);
rep(i,0,limit-1)a[i]=1ll*a[i]*b[i]%mod;
NTT(a,-1);
ll INV=qp(limit,mod-2);
rep(i,0,limit-1)a[i]=a[i]*INV%mod;
a.resize(n); return a;
}
ll fac[N],inv[N];
void add(ll &x,ll y){x=(x+y)%mod;}
void dif(ll &x,ll y){x=(x-y+mod)%mod;}
signed main(){
const int M=2e6;
fac[0]=1; rep(i,1,M)fac[i]=i*fac[i-1]%mod;
inv[M]=qp(fac[M],mod-2); per(i,M,1)inv[i-1]=inv[i]*i%mod;
int _,n; cin>>n;
int v[8],s[9]={0};
rep(i,0,2){
cin>>v[i*2]>>v[i*2+1]>>_;
}
v[6]=n;
rep(i,0,6){
int sum=0;
rep(j,0,6)sum+=K[i][j]*v[j];
if(sum%3){
cout<<0; return 0;
}
s[i]=sum/3;
}
auto wk=[&](int v1,int v2,int v3){
int l=max({-v1,-v2,-v3}),r=n+min({-v1,-v2,-v3});
if(l>r){
cout<<0; exit(0);
}
int len=r-l+1;
// cout<<v1<<' '<<v2<<' '<<v3<<' '<<l<<' '<<r<<'\n';
vi f(len);
rep(i,0,len-1){
int x=i+l;
f[i]=inv[v1+x]*inv[v2+x]%mod*inv[v3+x]%mod;
// if(i%10000==0)cout<<i<<' ';
}
// cout<<f.size()<<'\n';
return make_pair(l,f);
};
auto [l1,f1]=wk(s[0],s[1],s[4]);
auto [l2,f2]=wk(s[2],s[3],0);
// exit(0);
auto [l3,f3]=wk(s[5],s[6],0);
int ls=l1+l2+l3; ls=-ls;
auto rsz=[&](poly &f){
if(f.size()>ls+1)f.resize(ls+1);
};
rsz(f1); rsz(f2); rsz(f3);
auto f=poly_mul(f1,f2);
rsz(f);
f=poly_mul(f,f3);
if(!(ls>=0 && ls<f.size())){
assert(0);
cout<<0; return 0;
}
cout<<fac[n]*f[ls]%mod;
}
/*
1500000
500000 500000 500000
500000 500000 500000
500000 500000 500000
3
1 1 1
1 1 1
1 1 1
18
333333
111111 111111 111111
111111 111111 111111
111111 111111 111111
383902959
2
2 0 0
1 1 0
1 0 1
*/
詳細信息
Test #1:
score: 100
Accepted
time: 17ms
memory: 39848kb
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: 37140kb
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: 96ms
memory: 48288kb
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: 382ms
memory: 77704kb
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: 364ms
memory: 80740kb
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: 16ms
memory: 58928kb
input:
1500000 1 0 1499999 1499999 1 0 0 1499999 1
output:
1500000
result:
ok 1 number(s): "1500000"
Test #7:
score: 0
Accepted
time: 32ms
memory: 62756kb
input:
1499999 0 749999 750000 750000 0 749999 749999 750000 0
output:
713966599
result:
ok 1 number(s): "713966599"
Test #8:
score: 0
Accepted
time: 14ms
memory: 38184kb
input:
1 1 0 0 0 0 1 0 1 0
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 17ms
memory: 40128kb
input:
1 0 1 0 0 1 0 0 1 0
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: 0
Accepted
time: 6ms
memory: 38252kb
input:
1 0 0 1 1 0 0 1 0 0
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 371ms
memory: 80568kb
input:
1499999 500000 500000 499999 499999 499999 500001 499999 499999 500001
output:
617065435
result:
ok 1 number(s): "617065435"
Test #12:
score: -100
Runtime Error
input:
2 1 1 0 0 0 2 0 0 2