# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
442847 | parsabahrami | Skyscraper (JOI16_skyscraper) | C++17 | 269 ms | 84748 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.
/* I do it for the glory */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 1e2 + 10, MOD = 1e9 + 7;
int dp[N][N][10 * N][3], A[N], n, L;
void add(int &x, int y) {
x += y;
if (x >= MOD) x -= MOD;
}
int main() {
scanf("%d%d", &n, &L);
dp[0][0][0][0] = 1;
if (n < 2) return !printf("1\n");
for (int i = 1; i <= n; i++)
scanf("%d", &A[i]);
sort(A + 1, A + n + 1);
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= L; k++) {
for (int t = 0; t <= min(j, 2); t++) {
int nk = k + (A[i] - A[i - 1]) * (2 * j - t);
if (nk > L) continue;
add(dp[i][j + 1][nk][t], 1ll * dp[i - 1][j][k][t] * (j + 1 - t) % MOD);
if (t < 2)
add(dp[i][j + 1][nk][t + 1], dp[i - 1][j][k][t] * (2ll - t) % MOD);
if (t < 2 && j)
add(dp[i][j][nk][t + 1], dp[i - 1][j][k][t] * (2ll - t) % MOD);
if (j > 1)
add(dp[i][j - 1][nk][t], 1ll * dp[i - 1][j][k][t] * (j - 1) % MOD);
if (j)
add(dp[i][j][nk][t], dp[i - 1][j][k][t] * 1ll * (2 * j - t) % MOD);
}
}
}
}
int ret = 0;
for (int i = 0; i <= L; i++)
add(ret, dp[n][1][i][2]);
printf("%d\n", ret);
return 0;
}
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... |