#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<utility>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<ext/rope>
#include<unordered_set>
#include<unordered_map>
using namespace std;
using namespace __gnu_cxx;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define fopen freopen("input.txt", "r", stdin)
#define pb push_back
#define enter "\n"
#define space " "
#define pr2(a,b) cout<<(a)<<" "<<(b)<<endl
#define pr3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define pr4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define prec(a) cout<<fixed;cout.precision(a);
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
const ll INF = 1e18;
const int inf = 1e9;
int n, m,s=inf,e,hs=inf,he;
ll pac[9000010],mod=1000000007,ipac[9000010],dp[3010][3010],w,h;
ll mypow(ll a, ll b){
ll ret=1;
while(b){
if(b&1) ret = ret*a%mod;
a = a*a%mod;
b>>=1;
}
return ret;
}
int main(){
fastio;
cin>>n>>m;
int p;
cin>>p;
for(int i=1;i<=p;i++){
int a, b;
cin>>a>>b;
hs=min(hs,a);
he=max(he,a);
s=min(s,b);
e=max(e,b);
}
pac[0]=1;
for(int i=1;i<=n*m;i++) pac[i]=pac[i-1]*i%mod;
ipac[n*m]=mypow(pac[n*m],mod-2);
for(int i=n*m-1;i>=1;i--) ipac[i]=ipac[i+1]*(i+1)%mod;
ipac[0]=1;
w = e-s+1;
h = he-hs+1;
dp[h][w]=1;
for(int i=h;i<=n;i++){
for(int j=w;j<=m;j++){
if(i==h&&j==w) continue;
dp[i][j]=(dp[i-1][j]*pac[j]%mod+dp[i][j-1]*pac[i]%mod)%mod;
}
}
ll ans = dp[n][m],ww=1,hh=1;
ans = ans*pac[w*h-p]%mod;
ww = pac[m-w]*ipac[s-1]%mod*ipac[m-e]%mod;
hh = pac[n-h]*ipac[hs-1]%mod*ipac[n-he]%mod;
ans = ans*ww%mod*hh%mod;
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
420 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
632 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1016 KB |
Output is correct |
2 |
Correct |
9 ms |
2168 KB |
Output is correct |
3 |
Correct |
12 ms |
3192 KB |
Output is correct |
4 |
Correct |
87 ms |
21880 KB |
Output is correct |
5 |
Correct |
83 ms |
20984 KB |
Output is correct |
6 |
Correct |
96 ms |
22008 KB |
Output is correct |
7 |
Correct |
104 ms |
28920 KB |
Output is correct |
8 |
Correct |
222 ms |
62968 KB |
Output is correct |
9 |
Correct |
511 ms |
141884 KB |
Output is correct |
10 |
Correct |
821 ms |
184972 KB |
Output is correct |
11 |
Correct |
667 ms |
162040 KB |
Output is correct |
12 |
Correct |
455 ms |
125684 KB |
Output is correct |
13 |
Correct |
44 ms |
12408 KB |
Output is correct |
14 |
Correct |
499 ms |
141388 KB |
Output is correct |
15 |
Correct |
905 ms |
207892 KB |
Output is correct |
16 |
Correct |
640 ms |
144760 KB |
Output is correct |
17 |
Correct |
522 ms |
146368 KB |
Output is correct |
18 |
Correct |
901 ms |
205216 KB |
Output is correct |