Submission #127860

# Submission time Handle Problem Language Result Execution time Memory
127860 2019-07-10T07:26:06 Z doowey Tents (JOI18_tents) C++14
100 / 100
327 ms 35960 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 3005;
const int MOD = (int)1e9 + 7;

int mult(int a, int b){
    return (a * 1ll * b) % MOD;
}

void add(int &a, int b){
    a = (a + b) % MOD;
}

int dp[N][N];

int solve(int i, int j){
    if(dp[i][j] != -1) return dp[i][j];
    dp[i][j] = 0;
    if(i == 0 || j == 0){
        dp[i][j] = 1;
    }
    else{
        add(dp[i][j], solve(i - 1, j));
        add(dp[i][j], mult(4 * j, solve(i - 1, j - 1)));
        if(j > 1) add(dp[i][j], mult(j * (j - 1) / 2, solve(i - 1, j - 2)));
        if(i > 1) add(dp[i][j], mult(mult(j, (i - 1)), solve(i - 2, j - 1)));
    }
    return dp[i][j];
}

int main(){
    fastIO;
    int n, m;
    cin >> n >> m;
    for(int i = 0 ; i <= n; i ++ ){
        for(int j = 0 ; 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 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 764 KB Output is correct
8 Correct 3 ms 1400 KB Output is correct
9 Correct 2 ms 888 KB Output is correct
10 Correct 4 ms 1656 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 5 ms 1916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 764 KB Output is correct
8 Correct 3 ms 1400 KB Output is correct
9 Correct 2 ms 888 KB Output is correct
10 Correct 4 ms 1656 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 5 ms 1916 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 10 ms 9848 KB Output is correct
15 Correct 209 ms 33172 KB Output is correct
16 Correct 6 ms 2808 KB Output is correct
17 Correct 25 ms 8104 KB Output is correct
18 Correct 51 ms 11128 KB Output is correct
19 Correct 247 ms 34892 KB Output is correct
20 Correct 184 ms 29304 KB Output is correct
21 Correct 108 ms 20116 KB Output is correct
22 Correct 121 ms 22520 KB Output is correct
23 Correct 84 ms 19960 KB Output is correct
24 Correct 327 ms 35960 KB Output is correct
25 Correct 233 ms 31096 KB Output is correct
26 Correct 280 ms 33784 KB Output is correct
27 Correct 315 ms 34936 KB Output is correct