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<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<=n;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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |