Submission #142734

#TimeUsernameProblemLanguageResultExecution timeMemory
142734gs18103마스코트 (JOI13_mascots)C++14
40 / 100
7 ms2684 KiB
#include <bits/stdc++.h> #define fi first #define se second #define all(v) (v).begin(), (v).end() #define eb emplace_back #define fastio ios::sync_with_stdio(false); cin.tie(NULL) #define INF 2000000000; #define LINF 1000000000000000000LL #define mod 1000000007 using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; int r, c; ll dp[55][55][55][55], fact[9090909]; ll f(int x1, int y1, int x2, int y2) { if(x1 < 1 || y1 < 1 || x2 > r || y2 > c) return 0; if(x1 == 1 && y1 == 1 && x2 == r && y2 == c) return 1; if(dp[x1][y1][x2][y2] != 0) return dp[x1][y1][x2][y2]; dp[x1][y1][x2][y2] += (fact[x2-x1+1] * f(x1, y1, x2, y2+1)) % mod; dp[x1][y1][x2][y2] += (fact[y2-y1+1] * f(x1, y1, x2+1, y2)) % mod; dp[x1][y1][x2][y2] += (fact[x2-x1+1] * f(x1, y1-1, x2, y2)) % mod; dp[x1][y1][x2][y2] += (fact[y2-y1+1] * f(x1-1, y1, x2, y2)) % mod; dp[x1][y1][x2][y2] %= mod; return dp[x1][y1][x2][y2]; } int main() { fastio; int n, mx = 0, my = 0, mix = 3030, miy = 3030; cin >> r >> c >> n; fact[0] = 1; for(int i = 1; i <= r * c; i++) { fact[i] = (fact[i-1] * i) % mod; } for(int i = 1, x, y; i <= n; i++) { cin >> x >> y; mix = min(mix, x); mx = max(mx, x); miy = min(miy, y); my = max(my, y); } cout << (f(mix, miy, mx, my) * fact[(mx-mix+1)*(my-miy+1)-n]) % mod; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...