답안 #475562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475562 2021-09-23T00:52:32 Z SirCovidThe19th Skyscraper (JOI16_skyscraper) C++17
100 / 100
466 ms 402980 KB
#include <bits/stdc++.h>
using namespace std; 
 
#define FOR(i, x, y) for (int i = x; i < y; i++)
 
int N, L, A[105], md = 1e9 + 7; long long dp[105][105][1005][5], ans;
 
int main(){
	cin >> N >> L;
	FOR(i, 1, N + 1) cin >> A[i];
	sort(A + 1, A + N + 1); dp[0][0][0][0] = 1;
	FOR(i, 0, N + 1) FOR(j, 0, N + 1) FOR(l, 0, L + 1) FOR(m, 0, 3){
		int dif = (A[i + 1] - A[i]) * (2 * j - m); 
		long long &DP = dp[i][j][l][m]; DP %= md;
		if (dif < 0 or l + dif > L) continue;

		if (j) dp[i + 1][j - 1][l + dif][m] += DP * (j - 1); //merge
		dp[i + 1][j + 1][l + dif][m] += DP * (j + 1 - m); //new
		dp[i + 1][j][l + dif][m] += DP * (2 * j - m); //append
 
		dp[i + 1][j][l + dif][m + 1] += DP * (2 - m); //append end
		dp[i + 1][j + 1][l + dif][m + 1] += DP * (2 - m); //create end
 
		if (i == N and j == 1 and m == 2) ans += DP, ans %= md;
	}	
	cout<<(N == 1 ? 1 : ans)<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 4 ms 3660 KB Output is correct
6 Correct 4 ms 3532 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 4 ms 3660 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 2124 KB Output is correct
3 Correct 1 ms 1740 KB Output is correct
4 Correct 2 ms 2124 KB Output is correct
5 Correct 2 ms 2124 KB Output is correct
6 Correct 2 ms 2124 KB Output is correct
7 Correct 2 ms 1576 KB Output is correct
8 Correct 2 ms 1712 KB Output is correct
9 Correct 2 ms 1996 KB Output is correct
10 Correct 2 ms 1996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 4 ms 3660 KB Output is correct
6 Correct 4 ms 3532 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 4 ms 3660 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 2 ms 1484 KB Output is correct
12 Correct 2 ms 2124 KB Output is correct
13 Correct 1 ms 1740 KB Output is correct
14 Correct 2 ms 2124 KB Output is correct
15 Correct 2 ms 2124 KB Output is correct
16 Correct 2 ms 2124 KB Output is correct
17 Correct 2 ms 1576 KB Output is correct
18 Correct 2 ms 1712 KB Output is correct
19 Correct 2 ms 1996 KB Output is correct
20 Correct 2 ms 1996 KB Output is correct
21 Correct 6 ms 9804 KB Output is correct
22 Correct 291 ms 228648 KB Output is correct
23 Correct 466 ms 402812 KB Output is correct
24 Correct 377 ms 338768 KB Output is correct
25 Correct 466 ms 402980 KB Output is correct
26 Correct 416 ms 379716 KB Output is correct
27 Correct 144 ms 139872 KB Output is correct
28 Correct 176 ms 162508 KB Output is correct
29 Correct 310 ms 271280 KB Output is correct
30 Correct 462 ms 402884 KB Output is correct