Submission #93516

# Submission time Handle Problem Language Result Execution time Memory
93516 2019-01-09T07:50:43 Z vatsalsharma376 Tents (JOI18_tents) C++14
100 / 100
113 ms 70776 KB
#include<cstdio>
#include<algorithm>

using namespace std;

const long long mod = 1000000007;

const int MAX_N = 3000;

long long dp[MAX_N + 1][MAX_N + 1];

int H, W;

long long C2(int x){
	return x * (x - 1) / 2;
}

long long solve(){
	for(int i = 0; i <= H; ++i){
		for(int j = 0; j <= W; ++j){
			if(i == 0 || j == 0){
				dp[i][j] = 1;
			}else{
				dp[i][j] = 0;
				dp[i][j] += dp[i][j - 1];
				dp[i][j] += 4ll * i * dp[i - 1][j - 1];
				if(i >= 2){
					long long tmp = C2(i);
					dp[i][j] += tmp * dp[i - 2][j - 1];
				}
				if(j >= 2){
					dp[i][j] += (long long)i * (j - 1) * dp[i - 1][j - 2];
				}
				dp[i][j] %= mod;
			}
		}
	}
	long long ans = dp[H][W] - 1;
	ans %= mod;
	ans += mod;
	ans %= mod;
	return ans;
}

int main(){
	scanf("%d%d", &H, &W);
	long long ans = solve();
	printf("%lld\n", ans);
	return 0;
}

Compilation message

tents.cpp: In function 'int main()':
tents.cpp:46:7: 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 2 ms 512 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 1144 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 1400 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 1528 KB Output is correct
9 Correct 2 ms 888 KB Output is correct
10 Correct 3 ms 1784 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 1144 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 1400 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 1528 KB Output is correct
9 Correct 2 ms 888 KB Output is correct
10 Correct 3 ms 1784 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 2168 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 7 ms 9592 KB Output is correct
15 Correct 72 ms 55160 KB Output is correct
16 Correct 7 ms 4060 KB Output is correct
17 Correct 19 ms 12792 KB Output is correct
18 Correct 24 ms 17144 KB Output is correct
19 Correct 90 ms 63048 KB Output is correct
20 Correct 74 ms 50936 KB Output is correct
21 Correct 50 ms 33728 KB Output is correct
22 Correct 50 ms 35420 KB Output is correct
23 Correct 33 ms 27112 KB Output is correct
24 Correct 113 ms 70776 KB Output is correct
25 Correct 91 ms 61176 KB Output is correct
26 Correct 102 ms 66552 KB Output is correct
27 Correct 110 ms 68900 KB Output is correct