Submission #632126

#TimeUsernameProblemLanguageResultExecution timeMemory
632126CDuong마스코트 (JOI13_mascots)C++14
40 / 100
3 ms852 KiB
/* #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(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...