QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#289273 | #6325. Peaceful Results | ccc | WA | 268ms | 64160kb | C++14 | 3.6kb | 2023-12-23 16:35:52 | 2023-12-23 16:35:53 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=15e5+155;
const int mod=998244353, G=3;
int ksm(int x,int y) { int ans=1; while(y) { if(y&1) ans=ans*x%mod; x=x*x%mod; y>>=1; } return ans; }
int Inv(int x) { return ksm(x,mod-2); }
const int invG=Inv(G);
int n,AR,AP,AS,BR,BP,BS,CR,CP,CS,really_n;
double a[10][10]; int y[7];
void Read() { scanf("%lld",&n); really_n=n; scanf("%lld%lld%lld",&AR,&AP,&AS); scanf("%lld%lld%lld",&BR,&BP,&BS); scanf("%lld%lld%lld",&CR,&CP,&CS); }
void init() {
a[1][1]=1; a[1][2]=1; a[1][3]=1; a[1][7]=AR-AS;
a[2][4]=1; a[2][5]=1; a[2][6]=1; a[2][7]=AP-AS;
a[3][1]=1; a[3][2]=-1; a[3][5]=1; a[3][6]=-1; a[3][7]=BR-BS;
a[4][2]=-1; a[4][3]=1; a[4][4]=1; a[4][6]=-1; a[4][7]=BP-BS;
a[5][1]=1; a[5][3]=-1; a[5][5]=-1; a[5][6]=1; a[5][7]=CR-CS;
a[6][2]=1; a[6][3]=-1; a[6][4]=1; a[6][5]=-1; a[6][7]=CP-CS;
}
void solve_gs() {
const double eps=1e-8;
int nukt=n; n=6;
for(int i=1;i<=n;i++) {
bool fbi=false;
for(int j=i;j<=n;j++) { if(fabs(a[j][i])>eps) { fbi=true; for(int k=1;k<=n+1;k++) swap(a[i][k],a[j][k]); break; } }
if(!fbi) { puts("0"); exit(0); }
for(int j=1;j<=n;j++) {
if(i==j) continue;
double num=a[j][i]/a[i][i];
for(int k=i;k<=n+1;k++) a[j][k]-=a[i][k]*num;
}
}
for(int i=1;i<=n;i++) {
double yi=a[i][n+1]/a[i][i];
if(yi!=floor(yi)) { puts("0"); exit(0); }
y[i]=yi;
}
n=nukt;
}
void solve1() {
Read();
init(); solve_gs();
// for(int i=1;i<=6;i++) printf("%lld ",y[i]);
}
int tr[N];
void NTT(int *f,bool Is) {
for(int i=0;i<n;i++) if(i<tr[i]) swap(f[i],f[tr[i]]);
for(int p=2;p<=n;p<<=1) {
int len=p>>1; int w_len_1=ksm( ( Is?G:invG ),(mod-1)/p );
for(int str=0;str<n;str+=p) {
int w_len_now=1;
for(int i=str;i<str+len;i++) {
int now=f[i+len]*w_len_now%mod;
f[i+len]=( f[i]-now+mod )%mod;
f[i]=( f[i]+now )%mod;
w_len_now = w_len_now * w_len_1 % mod;
}
}
}
}
int jc[N],inv[N];
int fa[N],fb[N],fc[N];
void INIT() {
jc[0]=1; for(int i=1;i<=n;i++) jc[i]=jc[i-1]*i%mod;
inv[n]=ksm(jc[n],mod-2);
for(int i=n-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
void solve2() {
n=AS;//ÏÖÔÚ¼ÆËãµÄÊdzöSµÄ²½Êý
int s1=max( 0ll,min(-y[1],-y[4]) ), s2=max( 0ll,min(-y[2],-y[5]) ), s3=max( 0ll,min(-y[3],-y[6]) );
//ÿһÏî¾ùΪÕýÕûÊý£¬ÓÖÒòΪyÊDzîÖµ£¬¿ÉµÃÉÏʽ
int m=n; n=1; while(n<=2*m) n<<=1;
for(int i=s1;i<=m;i++) fa[i]=inv[i]*inv[i+y[1]]%mod*inv[i+y[4]]%mod;
for(int i=s2;i<=m;i++) fb[i]=inv[i]*inv[i+y[2]]%mod*inv[i+y[5]]%mod;
for(int i=s3;i<=m;i++) fc[i]=inv[i]*inv[i+y[3]]%mod*inv[i+y[6]]%mod;
for(int i=0;i<n;i++) tr[i]=(tr[i>>1]>>1)|((i&1)?n>>1:0);
NTT(fa,true); NTT(fb,true); NTT(fc,true);
for(int i=0;i<n;i++) fa[i]=fa[i]*fb[i]%mod*fc[i]%mod;
NTT(fa,false);
// for(int i=0;i<n;i++) cout<<fa[i]<<" ";
int ans=fa[m]*Inv(n)%mod*jc[really_n]%mod;
printf("%lld",ans);
}
void solve3() {
int s1=max( 0ll,min(-y[1],-y[4]) ), s2=max( 0ll,min(-y[2],-y[5]) ), s3=max( 0ll,min(-y[3],-y[6]) );
// for(int i=1;i<=6;i++) cout<<y[i]<<" ";
int ans=0;
for(int i=s1;i<=n;i++) {
for(int j=s2;j<=n;j++) {
for(int k=s3;k<=n;k++) {
if(i+j+k!=n) continue;
cout<<i<<" "<<j<<" "<<k<<endl;
int mul=jc[i]*jc[j]%mod*jc[k]%mod;
mul=mul*jc[i+y[1]]%mod*jc[i+y[4]]%mod;
mul=mul*jc[j+y[2]]%mod*jc[j+y[5]]%mod;
mul=mul*jc[k+y[3]]%mod*jc[k+y[6]]%mod;
cout<<Inv(mul)*jc[n]%mod<<" ";
ans+=Inv(mul)*jc[n]%mod;
}
}
} printf("%lld",ans);
}
#undef int
int main() {
solve1();
INIT();
solve2();
// solve3();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 14184kb
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: 0ms
memory: 3880kb
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: 60ms
memory: 26040kb
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: 258ms
memory: 64160kb
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: 268ms
memory: 62976kb
input:
1499999 499999 499999 500001 499999 499999 500001 499999 499999 500001
output:
934301164
result:
ok 1 number(s): "934301164"
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3796kb
input:
1500000 1 0 1499999 1499999 1 0 0 1499999 1
output:
0
result:
wrong answer 1st numbers differ - expected: '1500000', found: '0'