Submission #529118

# Submission time Handle Problem Language Result Execution time Memory
529118 2022-02-22T07:24:36 Z 8e7 Tents (JOI18_tents) C++17
100 / 100
138 ms 117280 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ...b ){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 3005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
void madd(int &x, int v) {
	x += v - mod; x += mod & (x>>31);
}
ll comb[maxn][maxn], fac[maxn], dp[maxn][maxn];
ll c(int n, int m) {
	if (m > n || m < 0) return 0;
	return comb[n][m];
}
int main() {
	io

	fac[0] = 1;
	for (int i = 1;i < maxn;i++) fac[i] = fac[i-1] * i % mod;
	comb[0][0] = 1;
	for (int i = 1;i < maxn;i++) {
		for (int j = 0;j <= i;j++) {
			comb[i][j] = (comb[i-1][j] + (j ? comb[i-1][j-1] : 0)) % mod;
		}
	}
	int n, m;
	cin >> n >> m;
	
	dp[0][0] = 1;
	for (int i = 0;i <= n;i++) {
		for (int j = 0;j <= m;j++) {
			if (i == 0 || j == 0) dp[i][j] = 1;
			else {
				if (i > 1) dp[i][j] += c(i, 2) * dp[i-2][j-1] % mod;
				if (j > 1) dp[i][j] += dp[i-1][j-2] * i % mod * (j - 1) % mod;
				dp[i][j] += 4 * i * dp[i-1][j-1] % mod;
				dp[i][j] += dp[i][j-1];
				dp[i][j] %= mod;
			}
		}
	}
	
	cout << (dp[n][m]+mod-1)%mod << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 25 ms 46660 KB Output is correct
2 Correct 27 ms 46668 KB Output is correct
3 Correct 24 ms 46808 KB Output is correct
4 Correct 24 ms 47508 KB Output is correct
5 Correct 32 ms 46984 KB Output is correct
6 Correct 30 ms 47800 KB Output is correct
7 Correct 25 ms 47172 KB Output is correct
8 Correct 25 ms 47756 KB Output is correct
9 Correct 24 ms 47228 KB Output is correct
10 Correct 25 ms 48116 KB Output is correct
11 Correct 24 ms 46788 KB Output is correct
12 Correct 27 ms 48548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 46660 KB Output is correct
2 Correct 27 ms 46668 KB Output is correct
3 Correct 24 ms 46808 KB Output is correct
4 Correct 24 ms 47508 KB Output is correct
5 Correct 32 ms 46984 KB Output is correct
6 Correct 30 ms 47800 KB Output is correct
7 Correct 25 ms 47172 KB Output is correct
8 Correct 25 ms 47756 KB Output is correct
9 Correct 24 ms 47228 KB Output is correct
10 Correct 25 ms 48116 KB Output is correct
11 Correct 24 ms 46788 KB Output is correct
12 Correct 27 ms 48548 KB Output is correct
13 Correct 24 ms 46660 KB Output is correct
14 Correct 35 ms 56164 KB Output is correct
15 Correct 102 ms 101528 KB Output is correct
16 Correct 29 ms 50436 KB Output is correct
17 Correct 41 ms 59180 KB Output is correct
18 Correct 45 ms 63428 KB Output is correct
19 Correct 111 ms 109388 KB Output is correct
20 Correct 102 ms 97320 KB Output is correct
21 Correct 71 ms 80236 KB Output is correct
22 Correct 71 ms 81828 KB Output is correct
23 Correct 52 ms 73432 KB Output is correct
24 Correct 138 ms 117280 KB Output is correct
25 Correct 114 ms 107636 KB Output is correct
26 Correct 128 ms 113096 KB Output is correct
27 Correct 133 ms 115356 KB Output is correct