bzoj4005[JLOI2015]骗我呢

时间:2023-03-09 09:13:48
bzoj4005[JLOI2015]骗我呢

http://www.lydsy.com/JudgeOnline/problem.php?id=4005

神题~远距离orz

膜拜PoPoQQQ大神

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>
#include<bitset>
#include<vector>
#include<functional>
#include<deque>
#include<cctype>
#include<climits>
#include<complex>
//#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj using namespace std; typedef long long LL;
typedef double DB;
typedef pair<int,int> PII;
typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a))
#define mmcy(a,b) memcpy(a,b,sizeof(a))
#define fill(a,l,r,v) fill(a+l,a+r+1,v)
#define re(i,a,b) for(i=(a);i<=(b);i++)
#define red(i,a,b) for(i=(a);i>=(b);i--)
#define ire(i,x) for(typedef(x.begin()) i=x.begin();i!=x.end();i++)
#define fi first
#define se second
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define SF scanf
#define PF printf
#define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;}
template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;}
template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} const DB EPS=1e-;
inline int sgn(DB x){if(abs(x)<EPS)return ;return(x>)?:-;}
const DB Pi=acos(-1.0); inline int gint()
{
int res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
}
inline LL gll()
{
LL res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
} const LL Mod=; LL N,M;
LL ans; inline LL power(LL a,LL k)
{
LL x=;
while(k){if(k&)x=x*a%Mod;a=a*a%Mod;k>>=;}
return x;
} LL S[]; inline LL C(LL N,LL M)
{
if(M< || M>N)return ;
LL x=S[N],y=S[N-M]*S[M]%Mod,res;
res=x*power(y,Mod-)%Mod;
res=(res%Mod+Mod)%Mod;
return res;
} //y=x+1
//y=x-M-2
inline void change(LL &x,LL &y,int f)
{
LL dx,dy;
if(f==)
{
dx=x;dy=y-;
x=dy;y=dx;
y++;
}
else
{
dx=x;dy=y+M+;
x=dy;y=dx;
y-=M+;
}
} int main()
{
freopen("bzoj4005.in","r",stdin);
freopen("bzoj4005.out","w",stdout);
LL i;
S[]=;re(i,,)S[i]=S[i-]*i%Mod;
N=gll(),M=gll();
ans=C(N+N+M+,N);LL x,y;int f;
x=N+M+;y=N;f=;
while()
{
change(x,y,f);
if(!(x>= && y>=))break;
if(f==) ans=(ans-C(x+y,x))%Mod; else ans=(ans+C(x+y,x))%Mod;
f^=;
}
x=N+M+;y=N;f=;
while()
{
change(x,y,f);
if(!(x>= && y>=))break;
if(f==) ans=(ans-C(x+y,x))%Mod; else ans=(ans+C(x+y,x))%Mod;
f^=;
}
ans=(ans%Mod+Mod)%Mod;
cout<<ans<<endl;
return ;
}