답안 #711220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711220 2023-03-16T10:22:13 Z Radin_Zahedi2 Tents (JOI18_tents) C++17
100 / 100
149 ms 35520 KB
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)x.size()
#define endl '\n'
const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const ll linf = 9e18 + 5;


int n, m;
const int N = 3e3 + 5;
const int M = 3e3 + 5;
int dp[N][M];

int mull(int a, int b) {
	return (1ll * a * b) % mod;
}

int c2(int n) {
	return (1ll * n * (n - 1)) / 2;
}

void init() {
}

void input() {
	cin >> n >> m;
}

void solve() {
	for (int j = 0; j <= m; j++) {
		dp[0][j] = 1;
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			dp[i][j] = dp[i - 1][j];

			if (j >= 1) {
				dp[i][j] += mull(mull(j, 4), dp[i - 1][j - 1]);
				dp[i][j] %= mod;
			}

			if (i >= 2) {
				dp[i][j] += mull(mull(j, i - 1), dp[i - 2][j - 1]);
				dp[i][j] %= mod;
			}

			if (i >= 1 && j >= 2) {
				dp[i][j] += mull(c2(j), dp[i - 1][j - 2]);
				dp[i][j] %= mod;
			}
		}
	}

	cout << dp[n][m] - 1;
}

void output() {
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int number_of_testcases = 1;
	//cin >> number_of_testcases;
	while (number_of_testcases--) {
		init();

		input();

		solve();

		output();
	}

	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 1224 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 2 ms 1620 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 1224 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 2 ms 1620 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 4 ms 9544 KB Output is correct
15 Correct 86 ms 32724 KB Output is correct
16 Correct 6 ms 2644 KB Output is correct
17 Correct 21 ms 7884 KB Output is correct
18 Correct 27 ms 11012 KB Output is correct
19 Correct 98 ms 34540 KB Output is correct
20 Correct 83 ms 29052 KB Output is correct
21 Correct 53 ms 19788 KB Output is correct
22 Correct 62 ms 22164 KB Output is correct
23 Correct 34 ms 19656 KB Output is correct
24 Correct 149 ms 35520 KB Output is correct
25 Correct 101 ms 30744 KB Output is correct
26 Correct 133 ms 33464 KB Output is correct
27 Correct 146 ms 34624 KB Output is correct