Submission #1033908

# Submission time Handle Problem Language Result Execution time Memory
1033908 2024-07-25T07:42:22 Z vjudge1 Tents (JOI18_tents) C++17
100 / 100
107 ms 70996 KB
// #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

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 time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 1436 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
10 Correct 1 ms 1880 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 1436 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
10 Correct 1 ms 1880 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 3 ms 9564 KB Output is correct
15 Correct 70 ms 55772 KB Output is correct
16 Correct 6 ms 4184 KB Output is correct
17 Correct 18 ms 13160 KB Output is correct
18 Correct 20 ms 17244 KB Output is correct
19 Correct 82 ms 62988 KB Output is correct
20 Correct 65 ms 51792 KB Output is correct
21 Correct 43 ms 34388 KB Output is correct
22 Correct 45 ms 36228 KB Output is correct
23 Correct 32 ms 27580 KB Output is correct
24 Correct 107 ms 70996 KB Output is correct
25 Correct 83 ms 61264 KB Output is correct
26 Correct 93 ms 66716 KB Output is correct
27 Correct 102 ms 69200 KB Output is correct