#include<stdio.h>
int x,y,q,n,m,minx=2147483647,miny=2147483647,maxx,maxy;
long long dap=1,d[3010][3010],fact[3010],comb[3010][3010];
int main()
{
int i,j;
scanf("%d %d",&n,&m);
scanf("%d",&q);
for(i=1;i<=q;i++)
{
scanf("%d %d",&x,&y);
if(minx>x) minx=x;
if(maxx<x) maxx=x;
if(miny>y) miny=y;
if(maxy<y) maxy=y;
}
fact[1]=1;
for(i=2;i<=3000;i++){fact[i]=fact[i-1]*i; fact[i]%=1000000007;}
for(i=1;i<=(maxx-minx+1)*(maxy-miny+1)-q;i++){dap*=i; dap%=1000000007;}
x=maxx-minx+1; y=maxy-miny+1;
comb[0][0]=1;
for(i=1;i<=3000;i++)
{
comb[i][0]=1;
for(j=1;j<=i;j++)
{
comb[i][j]=comb[i-1][j]+comb[i-1][j-1];
comb[i][j]%=1000000007;
}
}
d[x][y]=1;
for(i=x;i<=n;i++)
{
for(j=y;j<=m;j++)
{
if(i>x) d[i][j]+=d[i-1][j]*fact[j];
if(j>y) d[i][j]+=d[i][j-1]*fact[i];
}
}
dap*=d[n][m]; dap%=1000000007;
dap*=comb[n-x][minx-1]; dap%=1000000007;
dap*=comb[m-y][miny-1]; dap%=1000000007;
printf("%lld",dap);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
142676 KB |
Output is correct |
2 |
Correct |
16 ms |
142676 KB |
Output is correct |
3 |
Correct |
16 ms |
142676 KB |
Output is correct |
4 |
Correct |
8 ms |
142676 KB |
Output is correct |
5 |
Correct |
24 ms |
142676 KB |
Output is correct |
6 |
Correct |
20 ms |
142676 KB |
Output is correct |
7 |
Correct |
24 ms |
142676 KB |
Output is correct |
8 |
Correct |
12 ms |
142676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
142676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
142676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |