#include <bits/stdc++.h>
#define ff(i,a,b) for(int i=(a), _b=(b); i<=_b; ++i)
#define gg(i,a,b) for(int i=(a), _b=(b); i>=_b; --i)
#define REP(i,b) for(int i=(0), _b=(b); i< _b; ++i)
#define endl '\n'
#define long long long
#define ALL(x) (x).begin(), (x).end()
#define Love(a) {cerr << #a << " = " << a << endl;}
#define _ << "," <<
#define BIT(i, x) (((x)>>(i))&1)
#define X first
#define Y second
#define NAME "MASCOTS"
using namespace std;
const int N = 2e3 + 7;
const int MOD = 1e9 + 7;
int n, m, k, a, b, c, d;
long p[N*N], ans, dp[N][N], CC[N][N];
void Enter() {
scanf("%d%d%d", &m, &n, &k);
a = N;
b = N;
ff(i, 1, k) {
int x , y;
scanf("%d%d", &x, &y);
a = min(a, x);
c = max(c, x);
b = min(b, y);
d = max(d, y);
}
p[0] = 1;
ff(i, 1, n*m) p[i] = p[i-1] * i % MOD;
ans = p[(c-a+1)*(d-b+1)-k];
}
inline void Add(long &a, long b) {
a += b;
if (a > MOD) a -= MOD;
}
void Init() {
int V = max(m, n);
ff(i, 0, V) CC[0][i] = 1;
ff(i, 1, V)
ff(j, i, V)
CC[i][j] = (CC[i-1][j-1] + CC[i][j-1]) % MOD;
}
void Process() {
Init();
dp[m][n] = 1;
gg(i, m, 1)
gg(j, n, 1) {
if (i < m) Add(dp[i][j], dp[i+1][j] * p[j] % MOD);
if (j < n) Add(dp[i][j], dp[i][j+1] * p[i] % MOD);
}
printf("%d", ans * dp[c-a+1][d-b+1] % MOD * CC[a-1][m-(c-a+1)] % MOD * CC[b-1][n-(d-b+1)] % MOD);
}
int main() {
//ios_base::sync_with_stdio(0); cin.tie(0);
//freopen(NAME".inp", "r", stdin);
//freopen(NAME".out", "w", stdout);
Enter();
Process();
return 0;
}
Compilation message
mascots.cpp: In function 'void Process()':
mascots.cpp:66:100: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
printf("%d", ans * dp[c-a+1][d-b+1] % MOD * CC[a-1][m-(c-a+1)] % MOD * CC[b-1][n-(d-b+1)] % MOD);
^
mascots.cpp: In function 'void Enter()':
mascots.cpp:25:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &m, &n, &k);
^
mascots.cpp:32:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
96424 KB |
Output is correct |
2 |
Correct |
0 ms |
96424 KB |
Output is correct |
3 |
Correct |
0 ms |
96424 KB |
Output is correct |
4 |
Correct |
0 ms |
96424 KB |
Output is correct |
5 |
Correct |
0 ms |
96424 KB |
Output is correct |
6 |
Correct |
0 ms |
96424 KB |
Output is correct |
7 |
Correct |
0 ms |
96424 KB |
Output is correct |
8 |
Correct |
0 ms |
96424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
96424 KB |
Output is correct |
2 |
Correct |
0 ms |
96424 KB |
Output is correct |
3 |
Correct |
0 ms |
96424 KB |
Output is correct |
4 |
Correct |
0 ms |
96424 KB |
Output is correct |
5 |
Correct |
0 ms |
96424 KB |
Output is correct |
6 |
Correct |
0 ms |
96424 KB |
Output is correct |
7 |
Correct |
0 ms |
96424 KB |
Output is correct |
8 |
Correct |
0 ms |
96424 KB |
Output is correct |
9 |
Correct |
0 ms |
96424 KB |
Output is correct |
10 |
Correct |
0 ms |
96424 KB |
Output is correct |
11 |
Correct |
0 ms |
96424 KB |
Output is correct |
12 |
Correct |
0 ms |
96424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
96424 KB |
Output is correct |
2 |
Correct |
6 ms |
96424 KB |
Output is correct |
3 |
Correct |
3 ms |
96424 KB |
Output is correct |
4 |
Correct |
16 ms |
96424 KB |
Output is correct |
5 |
Correct |
26 ms |
96424 KB |
Output is correct |
6 |
Correct |
53 ms |
96424 KB |
Output is correct |
7 |
Correct |
46 ms |
96424 KB |
Output is correct |
8 |
Correct |
129 ms |
96424 KB |
Output is correct |
9 |
Runtime error |
36 ms |
96424 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |