답안 #527540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527540 2022-02-17T15:21:04 Z rainboy 마스코트 (JOI13_mascots) C
100 / 100
146 ms 69084 KB
#include <stdio.h>

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

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

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

void init() {
	int i;

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

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

int main() {
	static int dp[N + 1][M + 1];
	int n, m, k, h, i, il, ir, j, jl, jr, a, a_, b, b_;

	init();
	scanf("%d%d%d", &n, &m, &k);
	il= n, ir = -1, jl = m, jr = -1;
	for (h = 0; h < k; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		il = min(il, i), ir = max(ir, i), jl = min(jl, j), jr = max(jr, j);
	}
	a_ = ir - il + 1, b_ = jr - jl + 1;
	dp[a_][b_] = ff[a_ * b_ - k];
	for (a = a_; a <= n; a++)
		for (b = b_; b <= m; b++) {
			if (a > a_)
				dp[a][b] = (dp[a][b] + (long long) dp[a - 1][b] * ff[b]) % MD;
			if (b > b_)
				dp[a][b] = (dp[a][b] + (long long) dp[a][b - 1] * ff[a]) % MD;
		}
	printf("%lld\n", (long long) dp[n][m] * choose(n - a_, il) % MD * choose(m - b_, jl) % MD);
	return 0;
}

Compilation message

mascots.c: In function 'main':
mascots.c:34:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d%d%d", &n, &m, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
mascots.c:37:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 35396 KB Output is correct
2 Correct 65 ms 35556 KB Output is correct
3 Correct 62 ms 35424 KB Output is correct
4 Correct 61 ms 35516 KB Output is correct
5 Correct 59 ms 35512 KB Output is correct
6 Correct 62 ms 35476 KB Output is correct
7 Correct 62 ms 35408 KB Output is correct
8 Correct 62 ms 35524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 35472 KB Output is correct
2 Correct 59 ms 35500 KB Output is correct
3 Correct 58 ms 35428 KB Output is correct
4 Correct 60 ms 35532 KB Output is correct
5 Correct 61 ms 35464 KB Output is correct
6 Correct 61 ms 35404 KB Output is correct
7 Correct 66 ms 35464 KB Output is correct
8 Correct 61 ms 35420 KB Output is correct
9 Correct 59 ms 35652 KB Output is correct
10 Correct 58 ms 35552 KB Output is correct
11 Correct 60 ms 35456 KB Output is correct
12 Correct 60 ms 35488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 35516 KB Output is correct
2 Correct 69 ms 36056 KB Output is correct
3 Correct 66 ms 36688 KB Output is correct
4 Correct 69 ms 41644 KB Output is correct
5 Correct 68 ms 40772 KB Output is correct
6 Correct 84 ms 39884 KB Output is correct
7 Correct 63 ms 36492 KB Output is correct
8 Correct 64 ms 35548 KB Output is correct
9 Correct 76 ms 36040 KB Output is correct
10 Correct 138 ms 68532 KB Output is correct
11 Correct 110 ms 57796 KB Output is correct
12 Correct 74 ms 36128 KB Output is correct
13 Correct 61 ms 36996 KB Output is correct
14 Correct 60 ms 35448 KB Output is correct
15 Correct 142 ms 69084 KB Output is correct
16 Correct 134 ms 60244 KB Output is correct
17 Correct 84 ms 39500 KB Output is correct
18 Correct 146 ms 67752 KB Output is correct