답안 #632126

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
632126 2022-08-19T13:17:17 Z CDuong 마스코트 (JOI13_mascots) C++14
40 / 100
3 ms 852 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#define int long long
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define pii pair<int, int>
using namespace std;
const int mxN = 3e3 + 5;
const int mod = 1e9 + 7;
struct doll{
    int x, y;
} a[mxN];
int r, c, n, f[mxN][mxN], fact[mxN], revfact[mxN];
int binpow(int x, int y){
    int res = 1;
    while(y != 0){
        if(y % 2 == 1) res = (res * x) % mod;
        x = (x * x) % mod;
        y /= 2;
    }
    return res;
}
void calcfact(){
    fact[0] = revfact[0] = 1;
    for(int i = 1; i < mxN; ++i){
        fact[i] = (fact[i - 1] * i) % mod;
        revfact[i] = binpow(fact[i], mod - 2);
    }
}
int kCr(int k, int r){
    int res = 1;
    res = (res * fact[r]) % mod;
    res = (res * revfact[k]) % mod;
    res = (res * revfact[r - k]) % mod;
    return res;
}
int factorial(int x){
    int res = 1;
    for(int i = 1; i <= x; ++i){
        res = (res * i) % mod;
    }
    return res;
}
void solve(){
    cin >> r >> c >> n;
    int minx, maxx, miny, maxy;
    maxy = maxx = INT_MIN;
    miny = minx = INT_MAX;
    for(int i = 1; i <= n; ++i){
        cin >> a[i].x >> a[i].y;
        maxx = max(maxx, a[i].x);
        minx = min(minx, a[i].x);
        miny = min(miny, a[i].y);
        maxy = max(maxy, a[i].y);
    }
    int disx = maxx - minx + 1, disy = maxy - miny + 1;
    int ans = disx * disy - n;
    ans = factorial(ans);
    //cout << disx << " " << disy << endl;
    f[r][c] = 1;
    calcfact();
    for(int i = r - 1; i >= disx; --i){
        f[i][c] = (f[i + 1][c] * fact[c]) % mod;
    }
    for(int i = c - 1; i >= disy; --i){
        f[r][i] = (f[r][i + 1] * fact[r]) % mod;
    }
    for(int i = r - 1; i >= disx; --i){
        for(int j = c - 1; j >= disy; --j){
            f[i][j] += (f[i + 1][j] * fact[j]) % mod;
            f[i][j] += (f[i][j + 1] * fact[i]) % mod;
            f[i][j] %= mod;
            //cout << i << " " << j << " " << f[i][j] << endl;
        }
    }
    ans = (ans * f[disx][disy]) % mod;
    ans = (ans * kCr(minx - 1, r - disx)) % mod;
    ans = (ans * kCr(miny - 1, c - disy)) % mod;
    cout << ans << endl;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("Bai3.inp", "r", stdin);
    //freopen("Bai3.out", "w", stdout);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Runtime error 3 ms 596 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -