Submission #543473

# Submission time Handle Problem Language Result Execution time Memory
543473 2022-03-30T17:12:50 Z jesus_coconut Tents (JOI18_tents) C++17
100 / 100
325 ms 36092 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) begin(a), end(a)
#define pb push_back
#define eb emplace_back
using namespace std;

using ll = long long;

int const MOD = 1e9 + 7;
int const N = 3009;
int inv2 = (MOD + 1) / 2;
int add(ll a, ll b) {
    ll ret = (a + b) % MOD;
    if (ret < 0) ret += MOD;
    return ret;
}

int mul(ll a, ll b) {
    ll ret = (a * b) % MOD;
    if (ret < 0) ret += MOD;
    return ret;
}

int memo[N][N];
int f(int n, int m) {
    if (n == 0 || m == 0) return 1;
    /*if (min(n, m) == 1) {
        if (m == 1) swap(n, m);
        int mC2 = mul(mul(m, m - 1), inv2);
        return add(mul(4, m), mC2);
    }*/
    if (memo[n][m] != -1) return memo[n][m];
    int mC2 = mul(mul(m, m - 1), inv2);
    memo[n][m] = 0;
    memo[n][m] = add(memo[n][m], f(n-1, m));
    memo[n][m] = add(memo[n][m], mul(mul(4, m), f(n - 1, m - 1)));
    if (m >= 2) memo[n][m] = add(memo[n][m], mul(mC2, f(n - 1, m - 2)));
    if (n >= 2) memo[n][m] = add(memo[n][m], mul(mul(m, n - 1), f(n - 2, m - 1)));
    return memo[n][m];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    for (auto &arr : memo)
        memset(arr, -1, sizeof arr);
    int H, W;
    cin >> H >> W;
    cout << add(f(H, W), -1) << '\n';


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35668 KB Output is correct
2 Correct 16 ms 35668 KB Output is correct
3 Correct 17 ms 35692 KB Output is correct
4 Correct 16 ms 35696 KB Output is correct
5 Correct 17 ms 35720 KB Output is correct
6 Correct 16 ms 35732 KB Output is correct
7 Correct 17 ms 35836 KB Output is correct
8 Correct 15 ms 35748 KB Output is correct
9 Correct 16 ms 35680 KB Output is correct
10 Correct 16 ms 35760 KB Output is correct
11 Correct 19 ms 35708 KB Output is correct
12 Correct 22 ms 35716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35668 KB Output is correct
2 Correct 16 ms 35668 KB Output is correct
3 Correct 17 ms 35692 KB Output is correct
4 Correct 16 ms 35696 KB Output is correct
5 Correct 17 ms 35720 KB Output is correct
6 Correct 16 ms 35732 KB Output is correct
7 Correct 17 ms 35836 KB Output is correct
8 Correct 15 ms 35748 KB Output is correct
9 Correct 16 ms 35680 KB Output is correct
10 Correct 16 ms 35760 KB Output is correct
11 Correct 19 ms 35708 KB Output is correct
12 Correct 22 ms 35716 KB Output is correct
13 Correct 16 ms 35632 KB Output is correct
14 Correct 16 ms 35924 KB Output is correct
15 Correct 203 ms 36040 KB Output is correct
16 Correct 21 ms 35776 KB Output is correct
17 Correct 35 ms 35756 KB Output is correct
18 Correct 60 ms 35864 KB Output is correct
19 Correct 245 ms 36056 KB Output is correct
20 Correct 195 ms 35880 KB Output is correct
21 Correct 122 ms 35924 KB Output is correct
22 Correct 123 ms 35956 KB Output is correct
23 Correct 85 ms 35956 KB Output is correct
24 Correct 325 ms 36092 KB Output is correct
25 Correct 234 ms 36020 KB Output is correct
26 Correct 283 ms 36048 KB Output is correct
27 Correct 303 ms 36052 KB Output is correct