Submission #1065477

# Submission time Handle Problem Language Result Execution time Memory
1065477 2024-08-19T08:13:04 Z phong Tents (JOI18_tents) C++17
100 / 100
195 ms 71300 KB
#include<bits/stdc++.h>

#define ll long long
#define int long long
const int nmax = 3e3 + 5, N = 1e6;
const ll oo = 1e9 + 1, base = 311;
const int lg = 19, M = 10;
const ll mod = 1e9 + 7, mod2 = 1e9 + 5277;
#define pii pair<int, int>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;

int n, m, dp[nmax][nmax];
ll mul(ll a, ll b){
    return a * b % mod;
}
ll calc(int n, int m){
    if(n == 0 || m == 0) return 1;
    if(n < 0 || m < 0) return 0;
    if(dp[n][m] != -1) return dp[n][m];
    ll &res = dp[n][m];
    res = calc(n - 1, m);
    if(m >= 2){
        res += mul(calc(n - 1, m - 2), 1ll * m * (m - 1) / 2);
        res %= mod;
    }
    if(n >= 2){
       res += mul(calc(n - 2, m - 1), 1ll * (n - 1) * m);
       res %= mod;
    }
    res += mul(calc(n - 1, m - 1) * 4, m);
    res %= mod;
    return res;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen("code.inp", "r", stdin);
//    freopen("code.out", "w", stdout);
    cin >> n >> m;
    memset(dp, -1, sizeof dp);
    cout << calc(n, m) - 1;
}
/*
3 1
*/

Compilation message

tents.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 71004 KB Output is correct
2 Correct 18 ms 71092 KB Output is correct
3 Correct 18 ms 71076 KB Output is correct
4 Correct 21 ms 71100 KB Output is correct
5 Correct 18 ms 71120 KB Output is correct
6 Correct 20 ms 70992 KB Output is correct
7 Correct 19 ms 71004 KB Output is correct
8 Correct 21 ms 71256 KB Output is correct
9 Correct 20 ms 71004 KB Output is correct
10 Correct 23 ms 71080 KB Output is correct
11 Correct 18 ms 71004 KB Output is correct
12 Correct 20 ms 71004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 71004 KB Output is correct
2 Correct 18 ms 71092 KB Output is correct
3 Correct 18 ms 71076 KB Output is correct
4 Correct 21 ms 71100 KB Output is correct
5 Correct 18 ms 71120 KB Output is correct
6 Correct 20 ms 70992 KB Output is correct
7 Correct 19 ms 71004 KB Output is correct
8 Correct 21 ms 71256 KB Output is correct
9 Correct 20 ms 71004 KB Output is correct
10 Correct 23 ms 71080 KB Output is correct
11 Correct 18 ms 71004 KB Output is correct
12 Correct 20 ms 71004 KB Output is correct
13 Correct 18 ms 70996 KB Output is correct
14 Correct 18 ms 71252 KB Output is correct
15 Correct 128 ms 71288 KB Output is correct
16 Correct 22 ms 70996 KB Output is correct
17 Correct 29 ms 71004 KB Output is correct
18 Correct 41 ms 71004 KB Output is correct
19 Correct 149 ms 71300 KB Output is correct
20 Correct 116 ms 71260 KB Output is correct
21 Correct 76 ms 71004 KB Output is correct
22 Correct 82 ms 71260 KB Output is correct
23 Correct 57 ms 71260 KB Output is correct
24 Correct 195 ms 71260 KB Output is correct
25 Correct 153 ms 71260 KB Output is correct
26 Correct 172 ms 71260 KB Output is correct
27 Correct 193 ms 71260 KB Output is correct