Submission #1033971

# Submission time Handle Problem Language Result Execution time Memory
1033971 2024-07-25T08:10:09 Z vjudge1 Tents (JOI18_tents) C++17
100 / 100
231 ms 59104 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define pll pair<long long, long long>
#define se second
#define isz(a) (int)a.size()
using namespace std;

const long long inf = 1e18;
const int maxn = 3e3 + 5;
const int mod = 1e9 + 7;

int n, m, divi;
int cc[maxn][maxn];

long long binpow(int x, int y){
    long long ans = 1;
    while (y){
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod; y >>= 1;
    }
    return ans;
}

int dp(int i, int j){
    if (i < 0 || j < 0) return 0;
    if (cc[i][j]) return cc[i][j];
    int &ans = cc[i][j];
    ans += dp(i - 1, j); ans %= mod;
    ans += dp(i - 1, j - 1) * 4 % mod * j % mod; ans %= mod;
    ans += dp(i - 1, j - 2) * j % mod * (j - 1) % mod * divi % mod; ans %= mod;
    ans += dp(i - 2, j - 1) * j % mod * (i - 1) % mod; ans %= mod;
    return ans;
}   

void solve(){
    cin >> n >> m;
    divi = binpow(2, mod - 2);
    for (int i = 0; i <= n; ++i) cc[i][0] = 1;
    for (int i = 0; i <= m; ++i) cc[0][i] = 1;
    int ans = (dp(n, m) - 1 + mod) % mod;
    cout << ans << "\n";
}   

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t = 1; // cin >> t;
    while (t--){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 3 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 3 ms 8540 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 4 ms 16732 KB Output is correct
15 Correct 159 ms 52924 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 16 ms 16988 KB Output is correct
18 Correct 40 ms 22260 KB Output is correct
19 Correct 183 ms 59104 KB Output is correct
20 Correct 149 ms 47952 KB Output is correct
21 Correct 89 ms 31828 KB Output is correct
22 Correct 108 ms 38708 KB Output is correct
23 Correct 68 ms 38696 KB Output is correct
24 Correct 231 ms 58960 KB Output is correct
25 Correct 183 ms 53096 KB Output is correct
26 Correct 214 ms 57424 KB Output is correct
27 Correct 225 ms 57676 KB Output is correct