Submission #243205

# Submission time Handle Problem Language Result Execution time Memory
243205 2020-06-30T14:33:27 Z pavel Tents (JOI18_tents) C++14
100 / 100
289 ms 35960 KB
#include <cstdio>


using namespace std;

const int MAXD = 3003;

int dp[MAXD][MAXD];

typedef long long ll;
const int MOD = 1000000007;

int ADD(ll a, ll b){
    return (a+b)%MOD;
}
int SUB(ll a, ll b){
    return (a+MOD-b)%MOD;
}
int MUL(ll a, ll b){
    return (a*b)%MOD;
}

int solve(int h, int w){
    int& r = dp[h][w];
    if(r == -1){
        if(h == 0 || w == 0){
            r = 1;
        }else{
            r = ADD(solve(h, w-1), MUL(4*h, solve(h-1, w-1)));
            if(h >= 2) r = ADD(r, MUL(h*(h-1)/2, solve(h - 2, w - 1)));
            if(w >= 2) r = ADD(r, MUL(h*(w-1), solve(h - 1, w - 2)));
        }
    }
    return r;
}

int main(){
    for(int i=0;i<MAXD;++i) for(int j=0;j<MAXD;++j) dp[i][j] = -1;
    int h,w;
    scanf("%d%d", &h, &w);
    printf("%d\n", SUB(solve(h, w), 1));
}

Compilation message

tents.cpp: In function 'int main()':
tents.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &h, &w);
     ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 35576 KB Output is correct
2 Correct 24 ms 35584 KB Output is correct
3 Correct 23 ms 35584 KB Output is correct
4 Correct 24 ms 35652 KB Output is correct
5 Correct 24 ms 35584 KB Output is correct
6 Correct 25 ms 35584 KB Output is correct
7 Correct 24 ms 35584 KB Output is correct
8 Correct 25 ms 35584 KB Output is correct
9 Correct 24 ms 35584 KB Output is correct
10 Correct 24 ms 35584 KB Output is correct
11 Correct 24 ms 35584 KB Output is correct
12 Correct 28 ms 35584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 35576 KB Output is correct
2 Correct 24 ms 35584 KB Output is correct
3 Correct 23 ms 35584 KB Output is correct
4 Correct 24 ms 35652 KB Output is correct
5 Correct 24 ms 35584 KB Output is correct
6 Correct 25 ms 35584 KB Output is correct
7 Correct 24 ms 35584 KB Output is correct
8 Correct 25 ms 35584 KB Output is correct
9 Correct 24 ms 35584 KB Output is correct
10 Correct 24 ms 35584 KB Output is correct
11 Correct 24 ms 35584 KB Output is correct
12 Correct 28 ms 35584 KB Output is correct
13 Correct 24 ms 35712 KB Output is correct
14 Correct 24 ms 35584 KB Output is correct
15 Correct 181 ms 35704 KB Output is correct
16 Correct 36 ms 35840 KB Output is correct
17 Correct 59 ms 35712 KB Output is correct
18 Correct 64 ms 35712 KB Output is correct
19 Correct 208 ms 35704 KB Output is correct
20 Correct 171 ms 35832 KB Output is correct
21 Correct 123 ms 35712 KB Output is correct
22 Correct 141 ms 35704 KB Output is correct
23 Correct 42 ms 35584 KB Output is correct
24 Correct 289 ms 35840 KB Output is correct
25 Correct 213 ms 35960 KB Output is correct
26 Correct 239 ms 35840 KB Output is correct
27 Correct 272 ms 35960 KB Output is correct