Submission #798080

# Submission time Handle Problem Language Result Execution time Memory
798080 2023-07-30T10:57:47 Z vjudge1 Tents (JOI18_tents) C++17
100 / 100
241 ms 71168 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 3002;
const ll mod = 1e9 + 7;

ll dp[N][N];

ll multi(ll a, ll b){
    return ((a % mod) * (b % mod)) % mod;
}

ll add(ll a, ll b){
    return (a + b) % mod;
}

ll f(ll x, ll y){
    if(x < 0 || y < 0) return 0;
    if(x == 0 || y == 0) return 1;

    auto &cur = dp[x][y];
    if(cur != -1) return cur;

    cur = add(
            add(
                add(
                    f(x - 1, y),
                    multi(4LL*y, f(x - 1, y - 1))
                ), 
                multi((y*(y - 1LL))/2LL, f(x - 1, y - 2))
            ), 
            multi(y*(x - 1LL), f(x - 2, y - 1))
        );

    return cur;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    memset(dp, -1, sizeof(dp));
    int h, w; cin >> h >> w;

    cout << (f(h, w) - 1LL + mod) % mod << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 70868 KB Output is correct
2 Correct 27 ms 70868 KB Output is correct
3 Correct 21 ms 70800 KB Output is correct
4 Correct 22 ms 70868 KB Output is correct
5 Correct 24 ms 70832 KB Output is correct
6 Correct 23 ms 70760 KB Output is correct
7 Correct 22 ms 70740 KB Output is correct
8 Correct 21 ms 70884 KB Output is correct
9 Correct 22 ms 70844 KB Output is correct
10 Correct 23 ms 70836 KB Output is correct
11 Correct 28 ms 70748 KB Output is correct
12 Correct 29 ms 70768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 70868 KB Output is correct
2 Correct 27 ms 70868 KB Output is correct
3 Correct 21 ms 70800 KB Output is correct
4 Correct 22 ms 70868 KB Output is correct
5 Correct 24 ms 70832 KB Output is correct
6 Correct 23 ms 70760 KB Output is correct
7 Correct 22 ms 70740 KB Output is correct
8 Correct 21 ms 70884 KB Output is correct
9 Correct 22 ms 70844 KB Output is correct
10 Correct 23 ms 70836 KB Output is correct
11 Correct 28 ms 70748 KB Output is correct
12 Correct 29 ms 70768 KB Output is correct
13 Correct 24 ms 70776 KB Output is correct
14 Correct 27 ms 71028 KB Output is correct
15 Correct 200 ms 71064 KB Output is correct
16 Correct 24 ms 70868 KB Output is correct
17 Correct 34 ms 70868 KB Output is correct
18 Correct 56 ms 70872 KB Output is correct
19 Correct 197 ms 71068 KB Output is correct
20 Correct 156 ms 71024 KB Output is correct
21 Correct 99 ms 70968 KB Output is correct
22 Correct 115 ms 71008 KB Output is correct
23 Correct 81 ms 71076 KB Output is correct
24 Correct 241 ms 71168 KB Output is correct
25 Correct 192 ms 71040 KB Output is correct
26 Correct 225 ms 70996 KB Output is correct
27 Correct 227 ms 71036 KB Output is correct