답안 #475040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475040 2021-09-20T17:05:29 Z SirCovidThe19th Skyscraper (JOI16_skyscraper) C++17
100 / 100
482 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 0 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 940 KB Output is correct
9 Correct 5 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 2 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 1484 KB Output is correct
8 Correct 2 ms 1740 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 0 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 940 KB Output is correct
9 Correct 5 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 2 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 1484 KB Output is correct
18 Correct 2 ms 1740 KB Output is correct
19 Correct 2 ms 1996 KB Output is correct
20 Correct 2 ms 1996 KB Output is correct
21 Correct 9 ms 9804 KB Output is correct
22 Correct 321 ms 228644 KB Output is correct
23 Correct 461 ms 402812 KB Output is correct
24 Correct 385 ms 338812 KB Output is correct
25 Correct 462 ms 402896 KB Output is correct
26 Correct 417 ms 379660 KB Output is correct
27 Correct 140 ms 139972 KB Output is correct
28 Correct 175 ms 162500 KB Output is correct
29 Correct 319 ms 271324 KB Output is correct
30 Correct 482 ms 402980 KB Output is correct