답안 #236887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236887 2020-06-03T16:17:19 Z islingr Tents (JOI18_tents) C++14
100 / 100
180 ms 72568 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];

signed main() {
	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] % M);
		}
	}
	cout << (dp[h][w] + M - 1) % M;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 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 Correct 5 ms 896 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 5 ms 1408 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 7 ms 2688 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 7 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 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 Correct 5 ms 896 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 5 ms 1408 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 7 ms 2688 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 7 ms 2688 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 8 ms 9728 KB Output is correct
15 Correct 120 ms 55800 KB Output is correct
16 Correct 12 ms 3968 KB Output is correct
17 Correct 33 ms 14200 KB Output is correct
18 Correct 39 ms 18944 KB Output is correct
19 Correct 142 ms 70392 KB Output is correct
20 Correct 108 ms 49400 KB Output is correct
21 Correct 74 ms 33516 KB Output is correct
22 Correct 75 ms 35064 KB Output is correct
23 Correct 52 ms 36472 KB Output is correct
24 Correct 180 ms 72568 KB Output is correct
25 Correct 139 ms 62712 KB Output is correct
26 Correct 168 ms 68216 KB Output is correct
27 Correct 176 ms 70520 KB Output is correct