Submission #614194

# Submission time Handle Problem Language Result Execution time Memory
614194 2022-07-30T21:36:53 Z dutinmeow Skyscraper (JOI16_skyscraper) C++17
100 / 100
149 ms 242540 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9, MOD = 1e9 + 7;

int main() {
	int N, L;
	cin >> N >> L;
	vector<int> A(N + 1);
	for (int i = 1; i <= N; i++)
		cin >> A[i];
	sort(A.begin() + 1, A.end());
	A.push_back(INF);
	if (N == 1) {
		cout << 1 << '\n';
		return 0;
	} 
	
	vector<vector<vector<array<long long, 3>>>> dp(N + 1, vector<vector<array<long long, 3>>>(N + 1, vector<array<long long, 3>>(L + 1)));
	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 <= 2; m++) {
					int d = (2 * j - m) * (A[i + 1] - A[i]);
					if (d > k || i + j + 1 - m > N)
						continue;
					long long &f = dp[i][j][k][m];
					f = 0;
					f += dp[i - 1][j - 1][k - d][m];
					f += m == 0 ? 0 : (3 - m) * dp[i - 1][j - 1][k - d][m - 1];
					f += (2 * j - m) * dp[i - 1][j][k - d][m];
					f += m == 0 ? 0 : (m == 1 ? 2 * j * dp[i - 1][j][k - d][m - 1] : (i == N ? dp[i - 1][j][k - d][m - 1] : (j - 1) * dp[i - 1][j][k - d][m - 1]));
					f += m == 0 ? j * (j + 1) * dp[i - 1][j + 1][k - d][m] : (m == 1 ? j * j * dp[i - 1][j + 1][k - d][m] : (i == N ? dp[i - 1][j + 1][k - d][m] : j * (j - 1) * dp[i - 1][j + 1][k - d][m]));
					f %= MOD;
				}
			}
		}
	}

	long long ans = 0;
	for (int k = 0; k <= L; k++)
		ans += dp[N][1][k][2];
	cout << ans % MOD << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 420 KB Output is correct
5 Correct 2 ms 2220 KB Output is correct
6 Correct 2 ms 2088 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 2132 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 812 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 420 KB Output is correct
5 Correct 2 ms 2220 KB Output is correct
6 Correct 2 ms 2088 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 2132 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 812 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 2 ms 1876 KB Output is correct
22 Correct 82 ms 122648 KB Output is correct
23 Correct 139 ms 238320 KB Output is correct
24 Correct 103 ms 180300 KB Output is correct
25 Correct 139 ms 241456 KB Output is correct
26 Correct 128 ms 205320 KB Output is correct
27 Correct 37 ms 59860 KB Output is correct
28 Correct 46 ms 73344 KB Output is correct
29 Correct 84 ms 139236 KB Output is correct
30 Correct 149 ms 242540 KB Output is correct