# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
360124 | LucaDantas | Skyscraper (JOI16_skyscraper) | C++17 | 2 ms | 876 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn = 110, maxl = 1e3+10, mod = 1e9+7;
int dp[maxn][maxn][maxl][3];
// dp(i, j, k, z) | i == current position | j == number of components
// k == value of the perm | z == number of ends filled
void add(int& a, long long b) {
b %= mod;
a += b;
if(a >= mod) a -= mod;
}
int main() {
int n, L; scanf("%d %d", &n, &L);
vector<int> a(n);
for(int& x : a)
scanf("%d", &x);
sort(a.begin(), a.end());
for(int i = 0; i <= L; i++)
dp[0][0][i][0] = 1;
for(int i = 0; i < n; i++) {
int dif = a[i] - (i?a[i-1]:0);
for(int j = 0; j <= i; j++) {
for(int k = 0; k <= L; k++) {
for(int z = 0; z <= min(j, 2); z++) {
if(k + 1ll * dif * (2*j - z) > 1ll*L) continue;
int val = k + dif * (2*j - z);
// Merge a component with one of the ends
if(j && z != 2)
add(dp[i+1][j][val][z+1], 1ll * dp[i][j][k][z] * (2-z));
// Create a new component one of the ends
if(z != 2)
add(dp[i+1][j+1][val][z+1], 1ll * dp[i][j][k][z] * (2-z));
// Merge two components in the middle
if(j >= 2)
add(dp[i+1][j-1][val][z], 1ll * dp[i][j][k][z] * (j-1));
// Append to an existing component
if(j)
add(dp[i+1][j][val][z], 1ll * dp[i][j][k][z] * (2*j - z));
// Create a new component in the middle
add(dp[i+1][j+1][val][z], 1ll * dp[i][j][k][z] * (j+1-z));
}
}
}
}
printf("%d\n", dp[n][1][L][2]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |