Submission #101639

# Submission time Handle Problem Language Result Execution time Memory
101639 2019-03-19T05:49:44 Z KCSC Tents (JOI18_tents) C++14
100 / 100
289 ms 35832 KB
#include <bits/stdc++.h>
using namespace std;

const int DIM = 3005;
const int MOD = 1000000007;

int dp[DIM][DIM];

int solve(int n, int m) {
    if (n < 0 || m < 0) {
        return 0; }
    if (n == 0 || m == 0) {
        return 1; }
    if (dp[n][m] != -1) {
        return dp[n][m]; }
    long long ans = 0;
    ans += solve(n - 1, m);
    ans += 4LL * solve(n - 1, m - 1) * m;
    ans += 1LL * solve(n - 1, m - 2) * m * (m - 1) / 2;
    ans += 1LL * solve(n - 2, m - 1) * m * (n - 1);
    return dp[n][m] = ans % MOD; }

int main(void) {
  //  freopen("tents.in", "r", stdin);
  //  freopen("tents.out", "w", stdout);
    int n, m; cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            dp[i][j] = -1; } }
    cout << (solve(n, m) - 1 + MOD) % MOD;
    return 0; }
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 4 ms 1408 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 4 ms 1408 KB Output is correct
9 Correct 3 ms 896 KB Output is correct
10 Correct 4 ms 1664 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 6 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 4 ms 1408 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 4 ms 1408 KB Output is correct
9 Correct 3 ms 896 KB Output is correct
10 Correct 4 ms 1664 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 6 ms 1920 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 11 ms 9856 KB Output is correct
15 Correct 196 ms 33144 KB Output is correct
16 Correct 7 ms 2688 KB Output is correct
17 Correct 26 ms 8064 KB Output is correct
18 Correct 56 ms 11136 KB Output is correct
19 Correct 218 ms 34808 KB Output is correct
20 Correct 164 ms 29440 KB Output is correct
21 Correct 101 ms 19956 KB Output is correct
22 Correct 101 ms 22492 KB Output is correct
23 Correct 70 ms 19960 KB Output is correct
24 Correct 289 ms 35832 KB Output is correct
25 Correct 195 ms 31076 KB Output is correct
26 Correct 213 ms 33784 KB Output is correct
27 Correct 240 ms 35020 KB Output is correct