#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);
if (n == 1) {
printf("1\n");
return 0;
}
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:42:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
552 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 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 |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 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 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
552 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
95 ms |
2740 KB |
Output is correct |
23 |
Correct |
150 ms |
3432 KB |
Output is correct |
24 |
Correct |
114 ms |
3420 KB |
Output is correct |
25 |
Correct |
171 ms |
3424 KB |
Output is correct |
26 |
Correct |
134 ms |
3428 KB |
Output is correct |
27 |
Correct |
39 ms |
1868 KB |
Output is correct |
28 |
Correct |
50 ms |
2024 KB |
Output is correct |
29 |
Correct |
92 ms |
2772 KB |
Output is correct |
30 |
Correct |
158 ms |
3428 KB |
Output is correct |