답안 #236885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236885 2020-06-03T16:12:12 Z islingr Tents (JOI18_tents) C++14
100 / 100
195 ms 72544 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() {
	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] % M);
		}
	}
	cout << (dp[h][w] + M - 1) % M;
}
# 결과 실행 시간 메모리 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 Correct 5 ms 1024 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 6 ms 2688 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 7 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 5 ms 1024 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 6 ms 2688 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 7 ms 2816 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 9 ms 9600 KB Output is correct
15 Correct 122 ms 55800 KB Output is correct
16 Correct 14 ms 4096 KB Output is correct
17 Correct 33 ms 14200 KB Output is correct
18 Correct 39 ms 19040 KB Output is correct
19 Correct 148 ms 70264 KB Output is correct
20 Correct 115 ms 49400 KB Output is correct
21 Correct 78 ms 33540 KB Output is correct
22 Correct 77 ms 35064 KB Output is correct
23 Correct 55 ms 36472 KB Output is correct
24 Correct 195 ms 72544 KB Output is correct
25 Correct 144 ms 62584 KB Output is correct
26 Correct 160 ms 68088 KB Output is correct
27 Correct 176 ms 70504 KB Output is correct