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;
template<typename T> inline void read(T &x){
x = 0; char ch;
while(!isdigit(ch=getchar()));
do{x=10*x+ch-'0';}while(isdigit(ch=getchar()));
}
template<typename T> inline void write(T x){
if(x<=9){ putchar(x+'0'); return;}
write(x/10); putchar(x%10+'0');
}
template<typename T> inline void writeln(T x){
write(x); putchar('\n');
}
typedef long long ll;
const int N = 3333;
const ll MOD = 1e9+7;
int row, col, n;
ll F[N][N], Fac[N*N], cur, res;
void init(){
Fac[0] = 1;
for(int i = 1; i <= row*col; i++) Fac[i] = (Fac[i-1]*(ll)i)%MOD;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
read(row); read(col);
init();
read(n);
int u = N, v = N, p = 0, q = 0;
for(int i = 1; i <= n; i++){
int x, y;
read(x); read(y);
u = min(u,x);
v = min(v,y);
p = max(p,x);
q = max(q,x);
}
int x = p-u+1;
int y = q-v+1;
cur = Fac[x*y-n];
F[x][y] = cur;
for(int i = x; i <= row; i++){
for(int j = y; j <= col; j++){
if(i==x&&j==y) continue;
ll num = (ll)min((i-x+1)*(j-y+1),(row-i+1)*(col-j+1));
F[i][j] = (num*(F[i-1][j]*Fac[j]+F[i][j-1]*Fac[i])%MOD)%MOD;
}
}
writeln(F[row][col]);
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... |