Submission #527540

#TimeUsernameProblemLanguageResultExecution timeMemory
527540rainboy마스코트 (JOI13_mascots)C11
100 / 100
146 ms69084 KiB
#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 (stderr)

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--;
      |   ^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...