Submission #236884

# Submission time Handle Problem Language Result Execution time Memory
236884 2020-06-03T16:11:13 Z islingr Tents (JOI18_tents) C++14
0 / 100
5 ms 1152 KB
#include <iostream>
using namespace std;

#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)

using ll = long long;

const int N = 3 << 10, M = 1e9 + 7;
ll dp[N][N];

void add(ll& x, ll y) {
	x = x + y;
	if (x < 0) x += M;
	if (M <= x) x -= M;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int h, w; cin >> h >> w;
	rep(i, 0, h) dp[i][0] = 1;
	rep(j, 0, w) dp[0][j] = 1;
	rep(i, 1, h) {
		rep(j, 1, w) {
			auto add = [&](ll x) {
				dp[i][j] += x;
				if (M <= dp[i][j]) dp[i][j] -= M;
			};
			if (i != 1) add(i * (i - 1) / 2 % M * dp[i - 2][j - 1] % M);
			add(4 * i * dp[i - 1][j - 1] % M);
			add(dp[i][j - 1]);
			if (j != 1) add(i * (j - 1) % M * dp[i - 1][j - 2]);
		}
	}
	cout << (dp[h][w] + M - 1) % M;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 1152 KB Output is correct
5 Incorrect 5 ms 896 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 1152 KB Output is correct
5 Incorrect 5 ms 896 KB Output isn't correct
6 Halted 0 ms 0 KB -