Submission #1033908

#TimeUsernameProblemLanguageResultExecution timeMemory
1033908vjudge1Tents (JOI18_tents)C++17
100 / 100
107 ms70996 KiB
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC targt("arch=skylake,avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7; 
const ll inf = 2e18;
const ll blocksz = 320;
const ll N = 3e3 + 8;
ll dp[N][N],n,m;	
ll C2(ll x){
	return (x*(x-1)/2)%mod;
}
void solve(){
	cin >> n >> m;
	for(ll j = 0; j <= m; j++) dp[0][j] = 1;
	for(ll i = 1; i <= n; i++){
		for(ll j = 0; j <= m; j++){
			dp[i][j] = dp[i-1][j-1]*4*j%mod;
			dp[i][j] = (dp[i][j]+dp[i-1][j])%mod;
			if(j > 1) dp[i][j] = (dp[i][j]+dp[i-1][j-2]*C2(j)%mod)%mod;
			if(i > 1) dp[i][j] = (dp[i][j]+dp[i-2][j-1]*(j*(i-1)%mod)%mod)%mod;
		}
	}
	cout << (dp[n][m]+mod-1)%mod;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);    
    if (fopen("test.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll T = 1;
    // cin >> T;
    for (ll i = 1; i <= T; i++){
        solve();
        cout << '\n';
    }
}

Compilation message (stderr)

tents.cpp: In function 'int main()':
tents.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tents.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...