답안 #952758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952758 2024-03-24T17:34:25 Z DylanSmith Skyscraper (JOI16_skyscraper) C++17
20 / 100
296 ms 19776 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);
					}
				}
			}
		}
		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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 5 ms 2908 KB Output is correct
6 Correct 4 ms 2504 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 5 ms 2748 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 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 1 ms 860 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 5 ms 2908 KB Output is correct
6 Correct 4 ms 2504 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 5 ms 2748 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 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 1 ms 860 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Incorrect 296 ms 19776 KB Output isn't correct
23 Halted 0 ms 0 KB -