Submission #952760

# Submission time Handle Problem Language Result Execution time Memory
952760 2024-03-24T17:35:28 Z DylanSmith Skyscraper (JOI16_skyscraper) C++17
100 / 100
780 ms 30488 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define lb(x,y) lower_bound(all(x),y)-begin(x)

mt19937 rng;

int mod = 1000000007;

void solve() {
	int N, L; cin >> N >> L;
	vector<int> arr(N);
	for (int i = 0; i < N; i++) cin >> arr[i];
	if (N == 1) {
		cout << 1 << "\n";
		return;
	}
	sort(all(arr));
	vector<vector<vector<vector<ll>>>> dp(N + 1, vector<vector<vector<ll>>>(L + 1, vector<vector<ll>>(2, vector<ll>(2, 0)))), nxt = dp;
	dp[0][0][0][0] = 1;
	for (int i = 0; i < N; i++) {
		if (i > 0) {
			for (int j = 0; j <= N; j++) for (int k = 0; k <= L; k++)
				for (int l = 0; l < 2; l++) for (int r = 0; r < 2; r++) nxt[j][k][l][r] = 0;
			for (int j = 0; j <= N; j++) {
				for (int k = 0; k <= L; k++) {
					for (int l = 0; l < 2; l++) {
						for (int r = 0; r < 2; r++) {
							// sum contribution
							int k2 = k + (arr[i] - arr[i - 1]) * (j * 2 - l - r);
							if (k2 < 0 || k2 > L) continue;
							nxt[j][k2][l][r] += dp[j][k][l][r];
							if (nxt[j][k2][l][r] >= mod) nxt[j][k2][l][r] -= mod;
						}
					}
				}
			}
			swap(dp, nxt);
		}
		for (int j = 0; j <= N; j++) for (int k = 0; k <= L; k++)
			for (int l = 0; l < 2; l++) for (int r = 0; r < 2; r++) nxt[j][k][l][r] = 0;
		for (int j = 0; j <= N; j++) {
			for (int k = 0; k <= L; k++) {
				for (int l = 0; l < 2; l++) {
					for (int r = 0; r < 2; r++) {
						// new component
						if (j < N) {
							nxt[j + 1][k][l][r] += dp[j][k][l][r] * (j + 1 - l - r);
							if (l == 0) nxt[j + 1][k][1][r] += dp[j][k][l][r];
							if (r == 0) nxt[j + 1][k][l][1] += dp[j][k][l][r];
						}
						// extend component
						nxt[j][k][l][r] += dp[j][k][l][r] * (2 * j - l - r);
						if (l == 0) nxt[j][k][1][r] += dp[j][k][l][r];
						if (r == 0) nxt[j][k][l][1] += dp[j][k][l][r];
						// merge components
						if (j > 0) nxt[j - 1][k][l][r] += dp[j][k][l][r] * (j - 1);
					}
				}
			}
		}
		for (int j = 0; j <= N; j++) {
			for (int k = 0; k <= L; k++) {
				for (int l = 0; l < 2; l++) {
					for (int r = 0; r < 2; r++) {
						nxt[j][k][l][r] %= mod;
					}
				}
			}
		}
		swap(dp, nxt);
	}
	ll res = 0;
	for (int k = 0; k <= L; k++) res += dp[1][k][1][1];
	res %= mod;
	cout << res << "\n";
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 6 ms 2988 KB Output is correct
6 Correct 5 ms 2652 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 6 ms 2652 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 6 ms 2988 KB Output is correct
6 Correct 5 ms 2652 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 6 ms 2652 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 4 ms 860 KB Output is correct
22 Correct 395 ms 19780 KB Output is correct
23 Correct 743 ms 29980 KB Output is correct
24 Correct 546 ms 22768 KB Output is correct
25 Correct 780 ms 30332 KB Output is correct
26 Correct 639 ms 25680 KB Output is correct
27 Correct 140 ms 7784 KB Output is correct
28 Correct 176 ms 9304 KB Output is correct
29 Correct 428 ms 17660 KB Output is correct
30 Correct 770 ms 30488 KB Output is correct