Submission #659768

#TimeUsernameProblemLanguageResultExecution timeMemory
659768MohammadAghilFences (JOI18_fences)C++17
0 / 100
27 ms46680 KiB
#include <bits/stdc++.h> // #pragma GCC optimize ("Ofast,unroll-loops") // #pragma GCC target ("avx2") using namespace std; typedef long long ll; typedef pair<int, int> pp; #define per(i,r,l) for(int i = (r); i >= (l); i--) #define rep(i,l,r) for(int i = (l); i < (r); i++) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define pb push_back #define ss second #define ff first void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);} void IOS(){ cin.tie(0) -> sync_with_stdio(0); // #ifndef ONLINE_JUDGE // #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl // freopen("inp.txt", "r", stdin); // freopen("out.txt", "w", stdout); // #else // #define er(args ...) 0 // #endif } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll mod = 1e9 + 7, maxn = 3e3 + 5, lg = 22, inf = ll(1e9) + 5; ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll,md);return k*k%md*(b&1ll?a:1)%md;} ll f[maxn][maxn]; ll C[maxn][maxn], G[maxn]; int main(){ IOS(); int n, m; cin >> n >> m; rep(i,0,n+1){ rep(j,0,m+1){ f[i][j] = 1; if(j && i) f[i][j] = (f[i][j-1] + 4ll*i*f[i-1][j-1])%mod; } } rep(i,0,maxn){ C[i][0] = 1; rep(j,1,i+1) C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod; } G[0] = 1; rep(i,1,maxn){ G[i] = 1ll*G[i-1]*i%mod*(2*i-1)%mod; } ll ans = mod - 1; rep(a,0,n+1){ rep(b,0,m+1){ if(2*a + b <= n && 2*b + a <= m){ ans += f[n - 2*a - b][m - 2*b - a]*C[m][a]%mod*C[n][2*a]%mod*G[a]%mod*C[n-2*a][b]%mod*C[m-a][2*b]%mod*G[b]%mod; ans %= mod; } } } cout << ans << '\n'; return 0-0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...