답안 #685213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685213 2023-01-23T17:10:19 Z ToniB Skyscraper (JOI16_skyscraper) C++17
100 / 100
136 ms 79536 KB
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 105;

int n, L, a[MAXN];
long long dp[MAXN][MAXN][1005][3];

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

	if(n == 1){
		cout << 1; return 0;
	}
	dp[0][0][0][0] = 1;

	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= i; ++j){
			for(int k = 0; k <= L; ++k){
				for(int m = 0; m < 3; ++m){
					// first i numbers, j components, k is sum, m endpoints filled
					int dif = (a[i + 1] - a[i]) * (2 * j - m);
					if(k < dif) continue;
					// create new component that isnt endpoint
					dp[i][j][k][m] += dp[i - 1][j - 1][k - dif][m];
					
					// create new component that is endpoint
					if(m) dp[i][j][k][m] += dp[i - 1][j - 1][k - dif][m - 1] * (3 - m);
					
					// append on edge of component
					dp[i][j][k][m] += dp[i - 1][j][k - dif][m] * (2 * j - m);
					
					// append end on component
					if(m == 1) dp[i][j][k][m] += dp[i - 1][j][k - dif][m - 1] * 2 * j;
					else if(m == 2){
						if(i < n) dp[i][j][k][m] += dp[i - 1][j][k - dif][m - 1] * (j - 1);
						else dp[i][j][k][m] += dp[i - 1][j][k - dif][m - 1];
					}
					
					// merge two components
					if(i == n){
						dp[i][j][k][m] += dp[i - 1][j + 1][k - dif][m];
					} else {
						dp[i][j][k][m] += dp[i - 1][j + 1][k - dif][m] * (j * (j + 1) - m * j);
					}

					dp[i][j][k][m] %= MOD;
				}
			}
		}
	}
	long long ans = 0;
	for(int i = 0; i <= L; ++i) ans += dp[n][1][i][2];
	cout << ans % MOD;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 980 KB Output is correct
6 Correct 2 ms 856 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 980 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 2 ms 732 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 1 ms 772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 980 KB Output is correct
6 Correct 2 ms 856 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 980 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 2 ms 852 KB Output is correct
15 Correct 2 ms 732 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 772 KB Output is correct
21 Correct 3 ms 3284 KB Output is correct
22 Correct 116 ms 67220 KB Output is correct
23 Correct 119 ms 78776 KB Output is correct
24 Correct 136 ms 76820 KB Output is correct
25 Correct 132 ms 79260 KB Output is correct
26 Correct 114 ms 73940 KB Output is correct
27 Correct 45 ms 42244 KB Output is correct
28 Correct 69 ms 48820 KB Output is correct
29 Correct 120 ms 74440 KB Output is correct
30 Correct 114 ms 79536 KB Output is correct