Submission #712477

# Submission time Handle Problem Language Result Execution time Memory
712477 2023-03-18T20:11:19 Z Antekb Tents (JOI18_tents) C++17
0 / 100
126 ms 35612 KB
#include<bits/stdc++.h>
 
//#pragma GCC optimize("Ofast")
#pragma GCC optimize("trapv")
 
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
 
using namespace std;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~~
 
template <typename H, typename T> 
ostream& operator<<(ostream& os, pair<H, T> m){
	return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H> 
ostream& operator<<(ostream& os, vector<H> V){
	os<<"{";
	for(int i=0; i<V.size(); i++){
		if(i)os<<" ";
		os<<V[i];
	}
	os<<"}";
	return os;
}
 
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
 
///~~~~~~~~~~~~~~~~~~~~~~~~~
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;
 
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const int N=3e3+5, INF=1e9+5, mod=1e9+7;
int pot(int a, int b){
	if(!b)return 1;
	if(b==1)return a;
	ll c=pot(a, b/2);
	c=(c*c)%mod;
	if(b&1)c=(c*a)%mod;
	return c;
}
int odw(int a){return pot(a, mod-2);}
int sil[N], sil2[N], odw2[N];
int dp[N][N];
int main(){
	//BOOST;
	sil[0]=1;
	for(int i=1; i<N; i++)sil[i]=(sil[i-1]*1ll*i)%mod;
	for(int i=1; i<N; i++)odw2[i]=odw(i);
	for(int i=0; i<N; i++)sil2[i]=odw(sil[i]);
	for(int i=0; i<N; i++)dp[0][i]=sil2[i];
	for(int i=1; i<N; i++){
		for(int j=0; j<N; j++){
			dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
			if(j+1<N)dp[i][j+1]=(4ll*dp[i-1][j])%mod;
		}
		for(int j=0; j<N; j++){
			dp[i][j]=(dp[i][j]*1ll*odw2[i])%mod;
		}
	}
	//deb(4*dp[2][2]-mod);
	int n, m;
	cin>>n>>m;
	ll ans=0;
	for(int i=0; i<=n; i++){
		for(int j=0; j<=m; j++){
			int a=n-i-2*j, b=m-j-2*i;
			for(int m=0; m<=a && m<=b; m++){
				ll part=pot(4, m);
				part=(part*sil2[m])%mod;
				part=(part*sil2[a-m])%mod;
				part=(part*sil2[b-m])%mod;
				part=(part*sil2[i])%mod;
				part=(part*sil2[2*i])%mod;
				part=(part*sil2[j])%mod;
				part=(part*sil2[2*j])%mod;
				ans+=part;
				//deb(i, j, a, b, part*12%mod, (48*part)%mod);
			}
		}
	}
	ans%=mod;
	ans=(ans*sil[n])%mod;
	ans=(ans*sil[m])%mod;
	cout<<(ans+mod-1)%mod;
}

# Verdict Execution time Memory Grader output
1 Correct 118 ms 35588 KB Output is correct
2 Incorrect 126 ms 35612 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 118 ms 35588 KB Output is correct
2 Incorrect 126 ms 35612 KB Output isn't correct
3 Halted 0 ms 0 KB -