Submission #513878

# Submission time Handle Problem Language Result Execution time Memory
513878 2022-01-17T20:34:44 Z couplefire Tents (JOI18_tents) C++17
100 / 100
223 ms 35620 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 3005;
const int MOD = 1000000007;

inline int add(int a, int b){return (a+b>=MOD)?a+b-MOD:a+b;}
inline void inc(int& a, int b){a = add(a, b);}
inline int sub(int a, int b){return (a-b<0)?a-b+MOD:a-b;}
inline void dec(int &a, int b){a = sub(a, b);}
inline int mul(int a, int b){return 1ll*a*b%MOD;}
inline void grow(int &a, int b){a = mul(a, b);}

int n, m, dp[N][N];

int main(){
    // freopen("a.in", "r", stdin);
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    for(int i = 0; i<=n; ++i)
        for(int j = 0; j<=m; ++j){
            if(i==0 || j==0)
                {dp[i][j] = 1; continue;}
            // no take - 0
            inc(dp[i][j], dp[i][j-1]);
            // no take - 1
            if(i>=2) inc(dp[i][j], mul(dp[i-1][j-1], 4*i-4));
            // no take - 2
            if(i>=3) inc(dp[i][j], mul(dp[i-2][j-1], (i-1)*(i-2)/2));
            // no take - 2*
            if(i>=2 && j>=2) inc(dp[i][j], mul(dp[i-1][j-2], (i-1)*(j-1)));
            // take - 0 0
            inc(dp[i][j], mul(dp[i-1][j-1], 4));
            // take - 1 0
            if(i>=2) inc(dp[i][j], mul(dp[i-2][j-1], i-1));
            // take - 0 1
            if(j>=2) inc(dp[i][j], mul(dp[i-1][j-2], j-1));
        }
    cout << sub(dp[n][m], 1) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 2 ms 704 KB Output is correct
8 Correct 1 ms 1344 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 1612 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 3 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 2 ms 704 KB Output is correct
8 Correct 1 ms 1344 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 1612 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 3 ms 1868 KB Output is correct
13 Correct 0 ms 324 KB Output is correct
14 Correct 4 ms 9548 KB Output is correct
15 Correct 141 ms 32760 KB Output is correct
16 Correct 9 ms 2636 KB Output is correct
17 Correct 34 ms 7828 KB Output is correct
18 Correct 52 ms 10992 KB Output is correct
19 Correct 177 ms 34444 KB Output is correct
20 Correct 125 ms 29080 KB Output is correct
21 Correct 85 ms 19780 KB Output is correct
22 Correct 104 ms 22188 KB Output is correct
23 Correct 50 ms 19672 KB Output is correct
24 Correct 223 ms 35620 KB Output is correct
25 Correct 160 ms 30712 KB Output is correct
26 Correct 185 ms 33456 KB Output is correct
27 Correct 211 ms 34652 KB Output is correct