답안 #553196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553196 2022-04-25T04:02:15 Z Jomnoi Skyscraper (JOI16_skyscraper) C++17
15 / 100
1 ms 980 KB
#include <bits/stdc++.h>
#define DEBUG false
using namespace std;

const int MAX_N = 105;
const int MAX_L = 1005;
const int MOD = 1e9 + 7;

int A[MAX_N];
long long dp[MAX_N][MAX_N][MAX_L][3];

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	int N, L;
	cin >> N >> L;
	for(int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	if(N == 1) { // the answer will be 0, so 0 is strictly less than or equal to L
		cout << 0;
		return 0;
	}

	sort(A + 1, A + N + 1);

	dp[1][1][0][0] = 1;
	dp[1][1][0][1] = 2;
	for(int i = 1; i < N; i++) {
		for(int j = 1; j <= i; j++) {
			for(int k = 0; k <= L; k++) {
				for(int z = 0; z <= 2; z++) {
					int nk = k + (2 * j - z) * (A[i + 1] - A[i]);
					if(nk > L) {
						continue;
					}

					if(z < 2) { // add i to end point
						dp[i + 1][j][nk][z + 1] += (2 - z) * dp[i][j][k][z]; // add i to the left or right most component to be an end point
						dp[i + 1][j][nk][z + 1] %= MOD;

						dp[i + 1][j + 1][nk][z + 1] = (2 - z) * dp[i][j][k][z]; // create new component to the left or right most
						dp[i + 1][j + 1][nk][z + 1] %= MOD;
					}
					
					dp[i + 1][j][nk][z] += (2 * j - z) * dp[i][j][k][z]; // add i to left or right most of some components
					dp[i + 1][j][nk][z] %= MOD;

					dp[i + 1][j + 1][nk][z] += (j + 1 - z) * dp[i][j][k][z]; // create new component
					dp[i + 1][j + 1][nk][z] %= MOD;

					dp[i + 1][j - 1][nk][z] += (j - 1) * dp[i][j][k][z]; // merge two components
					dp[i + 1][j - 1][nk][z] %= MOD;
				}
			}
		}
	}

	long long ans = 0;
	for(int k = 0; k <= L; k++) {
		ans += dp[N][1][k][2];
		ans %= MOD;
	}
	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 944 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -