답안 #678834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678834 2023-01-06T16:31:47 Z rainboy Tents (JOI18_tents) C
100 / 100
255 ms 35568 KB
#include <stdio.h>

#define N	3000
#define M	3000
#define MD	1000000007

int vv[N + 1], ff[N + 1], gg[N + 1], dp[N + 1][M + 1];

void init() {
	int i, j;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= N; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
		ff[i] = (long long) ff[i - 1] * i % MD;
		gg[i] = (long long) gg[i - 1] * vv[i] % MD;
	}
	for (i = 0; i <= N; i++)
		for (j = 0; j <= M; j++)
			if (i == 0)
				dp[i][j] = j == 0 ? 1 : 0;
			else
				dp[i][j] = (dp[i - 1][j] + (j == 0 ? 0 : (long long) dp[i - 1][j - 1] * j * 2) + (j < 2 ? 0 : (long long) dp[i - 1][j - 2] * j * (j - 1) / 2)) % MD;
}

int choose(int n, int k) {
	return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}

int main() {
	int n, m, i, j, ans;

	init();
	scanf("%d%d", &n, &m);
	ans = 0;
	for (i = 0; i <= n; i++)
		for (j = 0; j <= m; j++)
			ans = (ans + (long long) dp[i][j] * dp[m - j][n - i] % MD * choose(n, i) % MD * choose(m, j) % MD) % MD;
	ans = (ans - 1 + MD) % MD;
	printf("%d\n", ans);
	return 0;
}

Compilation message

tents.c: In function 'main':
tents.c:34:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 35544 KB Output is correct
2 Correct 42 ms 35548 KB Output is correct
3 Correct 42 ms 35512 KB Output is correct
4 Correct 43 ms 35552 KB Output is correct
5 Correct 43 ms 35528 KB Output is correct
6 Correct 42 ms 35532 KB Output is correct
7 Correct 43 ms 35520 KB Output is correct
8 Correct 43 ms 35540 KB Output is correct
9 Correct 45 ms 35512 KB Output is correct
10 Correct 43 ms 35480 KB Output is correct
11 Correct 47 ms 35484 KB Output is correct
12 Correct 44 ms 35520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 35544 KB Output is correct
2 Correct 42 ms 35548 KB Output is correct
3 Correct 42 ms 35512 KB Output is correct
4 Correct 43 ms 35552 KB Output is correct
5 Correct 43 ms 35528 KB Output is correct
6 Correct 42 ms 35532 KB Output is correct
7 Correct 43 ms 35520 KB Output is correct
8 Correct 43 ms 35540 KB Output is correct
9 Correct 45 ms 35512 KB Output is correct
10 Correct 43 ms 35480 KB Output is correct
11 Correct 47 ms 35484 KB Output is correct
12 Correct 44 ms 35520 KB Output is correct
13 Correct 43 ms 35540 KB Output is correct
14 Correct 43 ms 35524 KB Output is correct
15 Correct 177 ms 35548 KB Output is correct
16 Correct 50 ms 35536 KB Output is correct
17 Correct 72 ms 35480 KB Output is correct
18 Correct 69 ms 35536 KB Output is correct
19 Correct 193 ms 35540 KB Output is correct
20 Correct 164 ms 35456 KB Output is correct
21 Correct 120 ms 35548 KB Output is correct
22 Correct 116 ms 35568 KB Output is correct
23 Correct 67 ms 35476 KB Output is correct
24 Correct 255 ms 35548 KB Output is correct
25 Correct 201 ms 35552 KB Output is correct
26 Correct 223 ms 35472 KB Output is correct
27 Correct 244 ms 35508 KB Output is correct