답안 #142734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
142734 2019-08-10T15:50:49 Z gs18103 마스코트 (JOI13_mascots) C++14
40 / 100
7 ms 2684 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 248 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 388 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 4 ms 1144 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 7 ms 2684 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 2168 KB Output isn't correct
2 Halted 0 ms 0 KB -