답안 #1043363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043363 2024-08-04T08:50:51 Z Aldas25 Skyscraper (JOI16_skyscraper) C++14
100 / 100
48 ms 129876 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;
const int MAXN = 110;
const int MAXL = 1010;

int n, l;
int a[MAXN];
ll dp[MAXN][MAXN][MAXL][3];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(nullptr);

	cin >> n >> l;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);

	if (n == 1) {
		cout << 1 << "\n";
		return 0;
	}

	dp[0][0][0][0] = 1;
	a[n+1] = MAXL;

	for (int i = 1; i <= n; i++) for (int j = 1; j <= i; j++) for (int m = 0; m <= 2; m++) {
		int delta = (a[i+1] - a[i]) * (2 * j - m);
		
		for (int k = delta; k <= l; k++) {
			int prevK = k - delta;
			ll val = 0;
			// Case 1
			val += dp[i-1][j-1][prevK][m];
			
			// Case 2
			if (m > 0) 
				val += ((ll)(3 - m)) * dp[i-1][j-1][prevK][m-1];

			// Case 3
			val += ((ll)(2 * j - m)) * dp[i-1][j][prevK][m];
			
			// Case 4
			if (m == 1) {
				val += ((ll)(2 * j)) * dp[i-1][j][prevK][m-1];
			} else if (m == 2 && j == 1 && i == n)
				val += dp[i-1][j][prevK][m-1];
			else if (m == 2 && j != 1)
				val += ((ll)(j-1)) * dp[i-1][j][prevK][m-1];

			// Case 5
			if (i == n && j == 1 && m == 2)
				val += dp[i-1][j+1][prevK][m];
			else if (i != n) {
				ll mult = 0;
				if (m == 0) mult = (j + 1) * j;
				else if (m == 1) mult = j * j;
				else mult = (j - 1) * j;

				val += mult * dp[i-1][j+1][prevK][m];
			}

			dp[i][j][k][m] = val % MOD;
		}
	}

	ll ans = 0;
	for (int k = 0; k <= l; k++) ans = (ans + dp[n][1][k][2]) % MOD;

	cout << (ans % MOD) << "\n";

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 2 ms 16760 KB Output is correct
6 Correct 2 ms 16732 KB Output is correct
7 Correct 1 ms 16872 KB Output is correct
8 Correct 1 ms 16732 KB Output is correct
9 Correct 2 ms 16732 KB Output is correct
10 Correct 1 ms 16848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 26972 KB Output is correct
2 Correct 3 ms 29020 KB Output is correct
3 Correct 3 ms 31068 KB Output is correct
4 Correct 2 ms 29020 KB Output is correct
5 Correct 2 ms 31068 KB Output is correct
6 Correct 3 ms 31068 KB Output is correct
7 Correct 3 ms 31068 KB Output is correct
8 Correct 2 ms 31068 KB Output is correct
9 Correct 3 ms 31068 KB Output is correct
10 Correct 2 ms 31152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 2 ms 16760 KB Output is correct
6 Correct 2 ms 16732 KB Output is correct
7 Correct 1 ms 16872 KB Output is correct
8 Correct 1 ms 16732 KB Output is correct
9 Correct 2 ms 16732 KB Output is correct
10 Correct 1 ms 16848 KB Output is correct
11 Correct 3 ms 26972 KB Output is correct
12 Correct 3 ms 29020 KB Output is correct
13 Correct 3 ms 31068 KB Output is correct
14 Correct 2 ms 29020 KB Output is correct
15 Correct 2 ms 31068 KB Output is correct
16 Correct 3 ms 31068 KB Output is correct
17 Correct 3 ms 31068 KB Output is correct
18 Correct 2 ms 31068 KB Output is correct
19 Correct 3 ms 31068 KB Output is correct
20 Correct 2 ms 31152 KB Output is correct
21 Correct 5 ms 61276 KB Output is correct
22 Correct 37 ms 117576 KB Output is correct
23 Correct 46 ms 129620 KB Output is correct
24 Correct 47 ms 127832 KB Output is correct
25 Correct 48 ms 129876 KB Output is correct
26 Correct 47 ms 124372 KB Output is correct
27 Correct 24 ms 97628 KB Output is correct
28 Correct 27 ms 103660 KB Output is correct
29 Correct 42 ms 126800 KB Output is correct
30 Correct 48 ms 129616 KB Output is correct