2022.7.19 AGC051D
作者:互联网
AGC051D C4
考虑给每条边定向,然后就是欧拉回路计数,套 \(\text{best}\) 定理即可。
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
const int maxn=1e6+10;
const int mod=998244353;
inline int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
return x*f;
}
const int N=1e6;
int n,a,b,c,d,fac[N+5],ifc[N+5],inv[N+5];
long long ans;
int main(){
a=read(),b=read(),c=read(),d=read();
if(((a&1)^(b&1))||((a&1)^(c&1))||(a&1)^(d&1))return puts("0")&0;
inv[1]=fac[0]=ifc[0]=1;
for(int i=2;i<=N;i++)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
for(int i=1;i<=N;i++)fac[i]=1ll*fac[i-1]*i%mod;
for(int i=1;i<=N;i++)ifc[i]=1ll*ifc[i-1]*inv[i]%mod;
for(int A=0;A<=a;A++){
int B=A-(a-b)/2,C=B-(b-c)/2,D=C-(c-d)/2;
if(B<0||C<0||D<0||B>b||C>c||D>d)continue;
//printf("%d %d %d %d\n",A,B,C,D);
int res=1ll*fac[A+b-B-1]*fac[B+c-C-1]%mod*fac[C+d-D-1]%mod*fac[D+a-A-1]%mod;
res=1ll*res*((1ll*(a-A)*(b-B)%mod*(c-C+D)+1ll*C*D%mod*(a-A+B))%mod)%mod;
res=1ll*res*ifc[A]%mod*ifc[a-A]%mod*ifc[B]%mod*ifc[b-B]%mod;
res=1ll*res*ifc[C]%mod*ifc[c-C]%mod*ifc[D]%mod*ifc[d-D]%mod;
res=1ll*res*(A+d-D)%mod;ans+=res;//printf("res=%d\n",res);
}printf("%lld\n",ans%mod);
return 0;
}
标签:AGC051D,19,res,int,1ll,fac,ifc,2022.7,mod 来源: https://www.cnblogs.com/syzf2222/p/16528309.html