답안 #208665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208665 2020-03-12T01:37:32 Z bensonlzl Skyscraper (JOI16_skyscraper) C++14
100 / 100
249 ms 260872 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll dp[105][105][1005][3];

ll N, L, A[105], D[105];

const ll mod = 1000000007;

ll calc(int n, int c, int l, int edge){
	if (l < 0) return 0;
	if (n == N) return ((c >= 1) && (c <= 2) && (c == edge));
	if (dp[n][c][l][edge] != -1) return dp[n][c][l][edge];
	ll ans = 0;
	if (edge < 2){
		// Add to one end of the array	
		ans += calc(n+1,c+1,l - (2 * (c+1) - edge - 1) * D[n],edge+1) * (2-edge);


		if (2*c - edge - 1 > 0) ans += calc(n+1,c,l - (2*c - edge - 1) * D[n],edge+1) * (2-edge);
	}
	// Add new segment
	if (c + 1 - edge > 0) ans += calc(n+1,c+1,l - (2*(c+1) - edge) * D[n], edge) * (c + 1 - edge);
	
	// Merge 2 existing segments
	if (c > 0) ans += calc(n+1,c-1,l - (2*(c-1) - edge) * D[n], edge) * (c-1);
	
	// Add to an existing segment
	if (2*c > edge) ans += calc(n+1,c,l - (2*c - edge) * D[n], edge) * (2 * c - edge);
	ans %= mod;
	return dp[n][c][l][edge] = ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	memset(dp,-1,sizeof(dp));
	cin >> N >> L;
	if (N == 1){
		cout << 1 << '\n';
		return 0;
	}
	for (int i = 1; i <= N; ++i){
		cin >> A[i];
	}
	sort(A+1,A+N+1);
	for (int i = 1; i <= N; ++i){
		D[i] = A[i+1] - A[i];
	}
	cout << calc(1,0,L,0) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 260604 KB Output is correct
2 Correct 146 ms 260524 KB Output is correct
3 Correct 149 ms 260600 KB Output is correct
4 Correct 145 ms 260872 KB Output is correct
5 Correct 135 ms 260600 KB Output is correct
6 Correct 145 ms 260512 KB Output is correct
7 Correct 142 ms 260600 KB Output is correct
8 Correct 145 ms 260600 KB Output is correct
9 Correct 139 ms 260472 KB Output is correct
10 Correct 145 ms 260508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 260472 KB Output is correct
2 Correct 152 ms 260472 KB Output is correct
3 Correct 141 ms 260576 KB Output is correct
4 Correct 144 ms 260560 KB Output is correct
5 Correct 138 ms 260600 KB Output is correct
6 Correct 136 ms 260472 KB Output is correct
7 Correct 139 ms 260472 KB Output is correct
8 Correct 149 ms 260472 KB Output is correct
9 Correct 157 ms 260576 KB Output is correct
10 Correct 140 ms 260600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 260604 KB Output is correct
2 Correct 146 ms 260524 KB Output is correct
3 Correct 149 ms 260600 KB Output is correct
4 Correct 145 ms 260872 KB Output is correct
5 Correct 135 ms 260600 KB Output is correct
6 Correct 145 ms 260512 KB Output is correct
7 Correct 142 ms 260600 KB Output is correct
8 Correct 145 ms 260600 KB Output is correct
9 Correct 139 ms 260472 KB Output is correct
10 Correct 145 ms 260508 KB Output is correct
11 Correct 140 ms 260472 KB Output is correct
12 Correct 152 ms 260472 KB Output is correct
13 Correct 141 ms 260576 KB Output is correct
14 Correct 144 ms 260560 KB Output is correct
15 Correct 138 ms 260600 KB Output is correct
16 Correct 136 ms 260472 KB Output is correct
17 Correct 139 ms 260472 KB Output is correct
18 Correct 149 ms 260472 KB Output is correct
19 Correct 157 ms 260576 KB Output is correct
20 Correct 140 ms 260600 KB Output is correct
21 Correct 146 ms 260448 KB Output is correct
22 Correct 249 ms 260600 KB Output is correct
23 Correct 186 ms 260600 KB Output is correct
24 Correct 197 ms 260504 KB Output is correct
25 Correct 178 ms 260604 KB Output is correct
26 Correct 194 ms 260716 KB Output is correct
27 Correct 165 ms 260472 KB Output is correct
28 Correct 172 ms 260576 KB Output is correct
29 Correct 201 ms 260588 KB Output is correct
30 Correct 178 ms 260492 KB Output is correct