Submission #999659

# Submission time Handle Problem Language Result Execution time Memory
999659 2024-06-16T03:05:11 Z overwatch9 Tents (JOI18_tents) C++17
48 / 100
2 ms 2396 KB
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll mod =  1000000007;
const int maxn = 300 + 1;
ll dp[maxn][maxn];
bool ready[maxn][maxn];
ll sum(ll x) {
    return ((x * (x-1)) / 2) % mod;
}
ll solve(ll h, ll w) {
    if (h < 0 || w < 0)
        return 0;
    if (h == 0 || w == 0)
        return 1;
    if (ready[h][w])
        return dp[h][w];
    ll ans = 0;
    // place nothing
    ans = solve(h-1, w);

    // place 1
    ans += (solve(h-1, w-1) * w * 4) % mod;
    ans %= mod;

    // place 2 in same row
    ans += (solve(h-1, w-2) * sum(w)) % mod;
    ans %= mod;

    // place 2 in same column
    ans += (solve(h-2, w-1) * (h-1) * w) % mod;
    ans %= mod;
    

    ready[h][w] = true;
    dp[h][w] = ans;
    return ans;
}
int main() {
    int h, w;
    cin >> h >> w;
    cout << (solve(h, w) - 1 + mod) % mod << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 1116 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Runtime error 2 ms 2396 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -