Submission #12968

# Submission time Handle Problem Language Result Execution time Memory
12968 2015-01-22T10:13:08 Z gs14004 마스코트 (JOI13_mascots) C++
100 / 100
524 ms 107012 KB
#include <cstdio>
#include <algorithm>
using namespace std;

int fact[9000005];
int dp[3005][3005];
int bino[3005][3005];
const int mod = 1e9 + 7;

int r,c,n;
int lx = 1e9, ly = 1e9, rx = -1, ry = -1;

int C(int x, int y){
    if(y == 0 || x == y) return 1;
    if(bino[x][y]) return bino[x][y];
    return bino[x][y] = (C(x-1,y-1) + C(x-1,y))%mod;
}

int f(int x, int y){
    if(x > r || y > c) return 0;
    if(x == r && y == c) return 1;
    if(dp[x][y]) return dp[x][y];
    long long t = 1ll * f(x,y+1) * fact[x] + 1ll * f(x+1,y) * fact[y];
    t %= mod;
    return dp[x][y] = t;
}

int main(){
    scanf("%d %d",&r,&c);
    fact[0] = 1;
    for (int i=1; i<r*c; i++) {
        fact[i] = 1ll * fact[i-1] * i % mod;
    }
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        int p,q;
        scanf("%d %d",&p,&q);
        lx = min(lx,p);
        ly = min(ly,q);
        rx = max(rx,p);
        ry = max(ry,q);
    }
    long long res = fact[(ry-ly+1)*(rx-lx+1) - n];
    res *= f(rx-lx+1,ry-ly+1);
    res %= mod;
    res *= 1ll * C(r - rx + lx - 1,lx - 1);
    res %= mod;
    res *= 1ll * C(c - ry + ly - 1,ly - 1);
    res %= mod;
    printf("%lld",res);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 106792 KB Output is correct
2 Correct 0 ms 106792 KB Output is correct
3 Correct 0 ms 106792 KB Output is correct
4 Correct 0 ms 106792 KB Output is correct
5 Correct 0 ms 106792 KB Output is correct
6 Correct 0 ms 106792 KB Output is correct
7 Correct 0 ms 106792 KB Output is correct
8 Correct 0 ms 106792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 106792 KB Output is correct
2 Correct 0 ms 106792 KB Output is correct
3 Correct 0 ms 106792 KB Output is correct
4 Correct 0 ms 106792 KB Output is correct
5 Correct 0 ms 106792 KB Output is correct
6 Correct 0 ms 106792 KB Output is correct
7 Correct 0 ms 106792 KB Output is correct
8 Correct 0 ms 106792 KB Output is correct
9 Correct 0 ms 106792 KB Output is correct
10 Correct 0 ms 106792 KB Output is correct
11 Correct 0 ms 106792 KB Output is correct
12 Correct 0 ms 106792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 106792 KB Output is correct
2 Correct 0 ms 106792 KB Output is correct
3 Correct 4 ms 106792 KB Output is correct
4 Correct 28 ms 106792 KB Output is correct
5 Correct 20 ms 106792 KB Output is correct
6 Correct 32 ms 106792 KB Output is correct
7 Correct 12 ms 106792 KB Output is correct
8 Correct 40 ms 106792 KB Output is correct
9 Correct 80 ms 106792 KB Output is correct
10 Correct 484 ms 107012 KB Output is correct
11 Correct 276 ms 106944 KB Output is correct
12 Correct 80 ms 106792 KB Output is correct
13 Correct 0 ms 106792 KB Output is correct
14 Correct 72 ms 106792 KB Output is correct
15 Correct 524 ms 107008 KB Output is correct
16 Correct 384 ms 106968 KB Output is correct
17 Correct 68 ms 106792 KB Output is correct
18 Correct 520 ms 107000 KB Output is correct