답안 #100456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100456 2019-03-11T11:19:34 Z JPN20 Tents (JOI18_tents) C++17
100 / 100
784 ms 141944 KB
#include <bits/stdc++.h>
using namespace std;

long long dp[3009][3009], nr[3009][3009], rem[3009], mod = 1000000007;

long long ncr(long long n, long long r) {
	if (r < 0 || n < r) return 0;
	return nr[n - r][r];
}

void init() {
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			if (i == 0 || j == 0) dp[i][j] = 1;
			else dp[i][j] = (1LL * dp[i - 1][j] + 4LL * j * dp[i - 1][j - 1]) % mod;
		}
	}
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			if (i == 0 || j == 0) nr[i][j] = 1;
			else nr[i][j] = (nr[i][j - 1] + nr[i - 1][j]) % mod;
		}
	}
	rem[0] = 1;
	for (int i = 1; i <= 1500; i++) {
		rem[i] = rem[i - 1] * ncr(i * 2, 2);
		rem[i] %= mod;
	}
}

long long product(vector<long long>E) {
	long long ans = 1;
	for (int i = 0; i < E.size(); i++) { ans *= E[i]; ans %= mod; }
	return ans;
}

long long H, W, sum;

int main() {
	cin >> H >> W; init();
	for (int i = 0; i <= H / 2; i++) {
		for (int j = 0; j <= W / 2; j++) {
			int c1 = H - i * 2 - j, c2 = W - i - j * 2;
			if (c1 < 0 || c2 < 0) continue;
			
			long long F1 = rem[i];
			long long F2 = rem[j];
			long long F3 = dp[c1][c2];
			long long F4 = ncr(H, i * 2);
			long long F5 = ncr(W, i);
			long long F6 = ncr(H - i * 2, j);
			long long F7 = ncr(W - i, j * 2);
			sum += product({F1, F2, F3, F4, F5, F6, F7});
			sum %= mod;
		}
	}
	cout << sum - 1 << endl;
	return 0;
}

Compilation message

tents.cpp: In function 'long long int product(std::vector<long long int>)':
tents.cpp:33:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < E.size(); i++) { ans *= E[i]; ans %= mod; }
                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 388 ms 141688 KB Output is correct
2 Correct 373 ms 141700 KB Output is correct
3 Correct 384 ms 141660 KB Output is correct
4 Correct 381 ms 141888 KB Output is correct
5 Correct 374 ms 141816 KB Output is correct
6 Correct 369 ms 141752 KB Output is correct
7 Correct 364 ms 141728 KB Output is correct
8 Correct 359 ms 141936 KB Output is correct
9 Correct 340 ms 141640 KB Output is correct
10 Correct 355 ms 141732 KB Output is correct
11 Correct 343 ms 141660 KB Output is correct
12 Correct 350 ms 141784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 388 ms 141688 KB Output is correct
2 Correct 373 ms 141700 KB Output is correct
3 Correct 384 ms 141660 KB Output is correct
4 Correct 381 ms 141888 KB Output is correct
5 Correct 374 ms 141816 KB Output is correct
6 Correct 369 ms 141752 KB Output is correct
7 Correct 364 ms 141728 KB Output is correct
8 Correct 359 ms 141936 KB Output is correct
9 Correct 340 ms 141640 KB Output is correct
10 Correct 355 ms 141732 KB Output is correct
11 Correct 343 ms 141660 KB Output is correct
12 Correct 350 ms 141784 KB Output is correct
13 Correct 363 ms 141756 KB Output is correct
14 Correct 368 ms 141680 KB Output is correct
15 Correct 627 ms 141944 KB Output is correct
16 Correct 424 ms 141752 KB Output is correct
17 Correct 444 ms 141688 KB Output is correct
18 Correct 429 ms 141772 KB Output is correct
19 Correct 718 ms 141688 KB Output is correct
20 Correct 653 ms 141816 KB Output is correct
21 Correct 524 ms 141816 KB Output is correct
22 Correct 489 ms 141836 KB Output is correct
23 Correct 378 ms 141688 KB Output is correct
24 Correct 772 ms 141844 KB Output is correct
25 Correct 701 ms 141688 KB Output is correct
26 Correct 723 ms 141916 KB Output is correct
27 Correct 784 ms 141908 KB Output is correct