Submission #655165

# Submission time Handle Problem Language Result Execution time Memory
655165 2022-11-03T13:02:34 Z ParsaS Tents (JOI18_tents) C++14
100 / 100
107 ms 35548 KB
// In the name of God
#pragma GCC optimize("O2", "unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
const int N = 3000 + 5, MOD = 1e9 + 7;
int n, m;
int dp[N][N];

int C2(int i) {
    return 1LL * i * (i - 1) / 2 % MOD;
}

void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        dp[i][1] = (i * 4 + C2(i) + 1) % MOD;
        dp[i][0] = 1;
    }
    for (int i = 1; i <= m; i++) {
        dp[1][i] = (i * 4 + C2(i) + 1) % MOD;
        dp[0][i] = 1;
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 2; j <= m; j++) {
            dp[i][j] = dp[i - 1][j];
            dp[i][j] = (dp[i][j] + 4LL * j * dp[i - 1][j - 1] % MOD) % MOD;
            dp[i][j] = (dp[i][j] + 1LL * C2(j) * dp[i - 1][j - 2] % MOD) % MOD;
            dp[i][j] = (dp[i][j] + 1LL * j * (i - 1) % MOD * dp[i - 2][j - 1] % MOD) % MOD;
        }
    }
    cout << (dp[n][m] - 1 + MOD) % MOD;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 1096 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 2 ms 1620 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 1096 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 2 ms 1620 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 4 ms 9572 KB Output is correct
15 Correct 71 ms 32844 KB Output is correct
16 Correct 6 ms 2644 KB Output is correct
17 Correct 18 ms 7932 KB Output is correct
18 Correct 21 ms 10948 KB Output is correct
19 Correct 80 ms 34504 KB Output is correct
20 Correct 66 ms 29072 KB Output is correct
21 Correct 49 ms 19752 KB Output is correct
22 Correct 44 ms 22200 KB Output is correct
23 Correct 27 ms 19668 KB Output is correct
24 Correct 107 ms 35548 KB Output is correct
25 Correct 86 ms 30740 KB Output is correct
26 Correct 104 ms 33436 KB Output is correct
27 Correct 104 ms 34612 KB Output is correct