Submission #553195

#TimeUsernameProblemLanguageResultExecution timeMemory
553195JomnoiSkyscraper (JOI16_skyscraper)C++17
15 / 100
1 ms852 KiB
#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]; int 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] += 1ll*(2 - z) * dp[i][j][k][z] % MOD; // 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] = 1ll*(2 - z) * dp[i][j][k][z] % MOD; // create new component to the left or right most dp[i + 1][j + 1][nk][z + 1] %= MOD; } dp[i + 1][j][nk][z] += 1ll*(2 * j - z) * dp[i][j][k][z] % MOD; // add i to left or right most of some components dp[i + 1][j][nk][z] %= MOD; dp[i + 1][j + 1][nk][z] += 1ll*(j + 1 - z) * dp[i][j][k][z] % MOD; // create new component dp[i + 1][j + 1][nk][z] %= MOD; dp[i + 1][j - 1][nk][z] += 1ll*(j - 1) * dp[i][j][k][z] % MOD; // merge two components dp[i + 1][j - 1][nk][z] %= MOD; } } } } int ans = 0; for(int k = 0; k <= L; k++) { ans += dp[N][1][k][2]; ans %= MOD; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...