Submission #391967

#TimeUsernameProblemLanguageResultExecution timeMemory
391967PixelCatTents (JOI18_tents)C++14
100 / 100
171 ms71108 KiB
/* /^--^\ \____/ / \ _____ _ __ __ ____ _ ____ ____ _____ | || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_ _| \__ __/ |_| |_|/_/\_\|____||____|\____)/__/\__\ |_| |^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^| | | |\ \| | | | | | | | | | | | | | | | | | | | | | | | | #####/ /################################################# | | |\/ | | | | | | | | | | | | | | | | | | | | | | | | | |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/ //#pragma GCC optimize("O4,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #define int ll //__int128 #define double long double using namespace std; using ll=long long; using ull=unsigned long long; using pii=pair<int,int>; #define For(i,a,b) for(int i=a;i<=b;i++) #define Fors(i,a,b,s) for(int i=a;i<=b;i+=s) #define Forr(i,a,b) for(int i=a;i>=b;i--) #define F first #define S second #define L(id) (id*2+1) #define R(id) (id*2+2) #define LO(x) (x&(-x)) #define eb emplace_back #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) #define mkp make_pair #define MOD (int)(1000000007) #define INF (int)(1e12) #define EPS (1e-7) #ifdef NYAOWO #define debug(...) do{\ cerr << __LINE__ <<\ " : ("#__VA_ARGS__ << ") = ";\ _OUT(__VA_ARGS__);\ cerr << flush;\ }while(0) template<typename T> void _OUT(T x) { cerr << x << "\n"; } template<typename T,typename...I> void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); } #else #define debug(...) #endif inline void NYA(){ ios::sync_with_stdio(false); cin.tie(0); } inline void USACO(const string &s){ freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); //int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } inline int gcd(int a,int b) { return __gcd(a,b); } inline int lcm(int a,int b) { return a/gcd(a,b)*b; } __int128 fpow(__int128 b,__int128 p,const __int128 &mod){ __int128 ans=1; while(p){ if(p&1) ans=ans*b%mod; p/=2; b=b*b%mod; } return ans; } int fpow(int b,int p) { return fpow(b,p,MOD); } template<typename T> inline void chmin(T &_a,const T &_b) { if(_b<_a) _a=_b; } template<typename T> inline void chmax(T &_a,const T &_b) { if(_b>_a) _a=_b; } int dp[3010][3010]; int fac[3010]; int inv[3010]; int C(int n,int m){ return fac[n]*inv[m]%MOD*inv[n-m]%MOD; } int32_t main(){ NYA(); //nachoneko so cute >/////< fac[0]=inv[0]=1; For(i,1,3000){ fac[i]=fac[i-1]*i%MOD; inv[i]=fpow(fac[i],MOD-2); } int n,m; cin>>n>>m; dp[0][0]=1; int ans=0; For(i,1,n) For(j,1,m){ dp[i][j]=dp[i-1][j-1]*4*j; if(i>=2) dp[i][j]+=dp[i-2][j-1]*(i-1)*j; if(j>=2) dp[i][j]+=dp[i-1][j-2]*j*(j-1)/2; dp[i][j]%=MOD; ans=(ans+dp[i][j]*C(n,i)%MOD*C(m,j))%MOD; debug(i,j,dp[i][j]); } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...