#include <stdio.h>
#define N 100
#define L 1000
#define MD 1000000007
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
void sort(int *aa, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;
while (j < k)
if (aa[j] == a)
j++;
else if (aa[j] < a) {
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
i++, j++;
} else {
k--;
tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
}
sort(aa, l, i);
l = k;
}
}
int main() {
static int aa[N], dp[N + 1][L + 1][2][2], dq[N + 1][L + 1][2][2];
int n, l, i, c, d, d_, s, t, a, ans;
scanf("%d%d", &n, &l);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
sort(aa, 0, n);
dp[0][0][0][0] = 1;
for (i = 0; i + 1 < n; i++) {
for (c = 0; c <= n; c++)
for (d = 0; d <= l; d++)
for (s = 0; s < 2; s++)
for (t = 0; t < 2; t++)
dq[c][d][s][t] = 0;
for (c = 0; c <= n; c++)
for (d = 0; d <= l; d++)
for (s = 0; s < 2; s++)
for (t = 0; t < 2; t++) {
int x = dp[c][d][s][t];
if (x == 0)
continue;
dq[c + 1][d][s][t] = (dq[c + 1][d][s][t] + x) % MD;
if (s == 0)
dq[c + 1][d][1][t] = (dq[c + 1][d][1][t] + x) % MD;
if (t == 0)
dq[c + 1][d][s][1] = (dq[c + 1][d][s][1] + x) % MD;
dq[c][d][s][t] = (dq[c][d][s][t] + (long long) x * (c * 2 - s - t)) % MD;
if (s == 0)
dq[c][d][1][t] = (dq[c][d][1][t] + (long long) x * (c - t)) % MD;
if (t == 0)
dq[c][d][s][1] = (dq[c][d][s][1] + (long long) x * (c - s)) % MD;
if (c > 0)
dq[c - 1][d][s][t] = (dq[c - 1][d][s][t] + (long long) x * ((c - s - t) * (c - s - t - 1) + (c - s - t) * (s + t))) % MD;
}
a = aa[i + 1] - aa[i];
for (c = 0; c <= n; c++)
for (d = 0; d <= l; d++)
for (s = 0; s < 2; s++)
for (t = 0; t < 2; t++)
if (s + t <= c * 2) {
d_ = a * (c * 2 - s - t);
dp[c][d][s][t] = d < d_ ? 0 : dq[c][d - d_][s][t];
}
}
ans = 0;
for (d = 0; d <= l; d++)
ans = ((long long) ans + dp[1][d][1][0] + dp[1][d][0][1] + dp[2][d][1][1]) % MD;
printf("%d\n", ans);
return 0;
}
Compilation message
skyscraper.c: In function 'main':
skyscraper.c:36:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d%d", &n, &l);
| ^~~~~~~~~~~~~~~~~~~~~
skyscraper.c:38:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |