Submission #529021

# Submission time Handle Problem Language Result Execution time Memory
529021 2022-02-22T01:42:40 Z wiwiho Tents (JOI18_tents) C++14
100 / 100
212 ms 70840 KB
#include<bits/stdc++.h>

#define printv(a, b) { \
    for(auto pv : a) b << pv << " "; \
    b << "\n"; \
}

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

ll C2(ll n){
    if(n < 2) return 0;
    return n * (n - 1) / 2;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1));
    for(int i = 0; i <= n; i++) dp[i][0] = 1;
    for(int i = 0; i <= m; i++) dp[0][i] = 1;
    for(int sz = 2; sz <= n + m; sz++){
        for(int i = 1; i < sz; i++){
            int j = sz - i;
            if(i > n || j > m) continue;

            if(j >= 2) dp[i][j] += dp[i - 1][j - 2] * i % MOD * (j - 1) % MOD;
            if(i >= 2) dp[i][j] += dp[i - 2][j - 1] * C2(i) % MOD;
            dp[i][j] += 4LL * i * dp[i - 1][j - 1] % MOD;
            dp[i][j] += dp[i][j - 1];
            dp[i][j] %= MOD;
        }
    }

    //for(int i = 0; i <= n; i++) printv(dp[i], cerr);

    ll ans = dp[n][m];
    ans--;
    ans = (ans % MOD + MOD) % MOD;

    cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 2 ms 436 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 572 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 2 ms 436 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 572 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 972 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 140 ms 44216 KB Output is correct
16 Correct 7 ms 3020 KB Output is correct
17 Correct 19 ms 10060 KB Output is correct
18 Correct 27 ms 12468 KB Output is correct
19 Correct 143 ms 51404 KB Output is correct
20 Correct 109 ms 41180 KB Output is correct
21 Correct 61 ms 27232 KB Output is correct
22 Correct 65 ms 26868 KB Output is correct
23 Correct 37 ms 15052 KB Output is correct
24 Correct 212 ms 70840 KB Output is correct
25 Correct 155 ms 52676 KB Output is correct
26 Correct 159 ms 60376 KB Output is correct
27 Correct 200 ms 68172 KB Output is correct