# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
528147 | buidangnguyen05 | Skyscraper (JOI16_skyscraper) | C++14 | 104 ms | 29412 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.
/* input
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 110, mod = 1e9 + 7;
int a[N], f[N][N][10 * N][3];
void add(int &x, int y) {
x += y;
if (x >= mod) x -= mod;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("task.inp", "r")) {
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
}
int n, mx; cin >> n >> mx;
for (int i = 1; i <= n; ++i) cin >> a[i];
if (n == 1) {
cout << "1\n";
exit(0);
}
sort (a + 1, a + n + 1); a[n + 1] = 1e5;
f[0][0][0][0] = 1;
for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
for (int k = 1; k <= mx; ++k) for (int m = 0; m < 3; ++m) {
int diff = (2 * j - m) * (a[i + 1] - a[i]);
if (diff > k || i + j + 1 - m > n) continue;
add(f[i][j][k][m], f[i - 1][j - 1][k - diff][m]);
if (m) add(f[i][j][k][m], 1LL * (3 - m) * f[i - 1][j - 1][k - diff][m - 1] % mod);
add(f[i][j][k][m], 1LL * (2 * j - m) * f[i - 1][j][k - diff][m] % mod);
if (m == 1) add(f[i][j][k][m], 2LL * j * f[i - 1][j][k - diff][m - 1] % mod);
else if (m == 2) {
if (i == n) add(f[i][j][k][m], f[i - 1][j][k - diff][m - 1]);
else add(f[i][j][k][m], 1LL * (j - 1) * f[i - 1][j][k - diff][m - 1] % mod);
}
if (m == 1) add(f[i][j][k][m], 1LL * j * j * f[i - 1][j + 1][k - diff][m] % mod);
else if (!m) add(f[i][j][k][m], 1LL * j * (j + 1) * f[i - 1][j + 1][k - diff][m] % mod);
else {
if (i == n) add(f[i][j][k][m], f[i - 1][j + 1][k - diff][m]);
else add(f[i][j][k][m], 1LL * j * (j - 1) * f[i - 1][j + 1][k - diff][m] % mod);
}
}
}
int res = 0;
for (int i = 0; i <= mx; ++i) add(res, f[n][1][i][2]);
cout << res << "\n";
}
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... |