This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int R = 3007;
const int MOD = 1e9 + 7;
int r, c, n, dp[R][R], fact[R * R], nCk[R][R];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
fact[0] = 1;
for(int i = 1; i < R * R; i++)
fact[i] = (ll) fact[i - 1] * i % MOD;
for(int i = 0; i < R; i++){
nCk[i][0] = 1;
for(int j = 1; j <= i; j++)
nCk[i][j] = (nCk[i - 1][j] + nCk[i - 1][j - 1]) % MOD;
}
cin >> r >> c >> n;
int minX = R, maxX = 0, minY = R, maxY = 0;
for(int i = 1; i <= n; i++){
int x, y;
cin >> x >> y;
minX = min(minX, x);
maxX = max(maxX, x);
minY = min(minY, y);
maxY = max(maxY, y);
}
int r0 = maxX - minX + 1;
int c0 = maxY - minY + 1;
dp[r0][c0] = fact[r0 * c0 - n];
for(int i = 1; i <= r; i++)
for(int j = 1; j <= c; j++){
if (i < r)
dp[i + 1][j] = (dp[i + 1][j] + (ll) dp[i][j] * fact[j]) % MOD;
if (j < c)
dp[i][j + 1] = (dp[i][j + 1] + (ll) dp[i][j] * fact[i]) % MOD;
}
cout << (ll) dp[r][c] * nCk[r - r0][minX - 1] % MOD * nCk[c - c0][minY - 1] % MOD;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |