#include <bits/stdc++.h>
using namespace std;
const int md = (int)1e9 + 7;
void add(int& a, int b) {
a += b;
if(a >= md) a -= md;
}
int mul(int a, int b) {
return (long long)a * b % md;
}
const int N = 102;
const int M = 1003;
int n, m, res, a[N], f[N][N][M][3];
int main() {
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i)
scanf("%d", a + i);
sort(a, a + n);
if(n == 1) {
putchar('1');
}
else {
f[0][1][0][0] = 1;
f[0][1][0][1] = 2;
for(int i = 0; i + 1 < n; ++i)
for(int j = 1; j <= n; ++j)
for(int k = 0; k <= m; ++k)
for(int l = 0; l < 3; ++l) {
int ft = f[i][j][k][l];
if(ft == 0) continue;
int nk = k + (2 * j - l) * (a[i + 1] - a[i]);
if(nk > m) continue;
add(f[i + 1][j + 1][nk][l], mul(ft, j + 1 - l));
if(l < 2) add(f[i + 1][j + 1][nk][l + 1], mul(ft, 2 - l));
if(j != l || i + 2 == n) {
add(f[i + 1][j - 1][nk][l], mul(ft, j - 1));
if(l < 2) add(f[i + 1][j][nk][l + 1], mul(ft, 2 - l));
}
add(f[i + 1][j][nk][l], mul(ft, 2 * j - l));
}
for(int i = 0; i <= m; ++i)
add(res, f[n - 1][1][i][2]);
printf("%d", res);
}
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d", a + i);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
428 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
424 KB |
Output is correct |
8 |
Correct |
1 ms |
676 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
428 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
432 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
620 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
424 KB |
Output is correct |
18 |
Correct |
1 ms |
676 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
2 ms |
1228 KB |
Output is correct |
22 |
Correct |
69 ms |
16600 KB |
Output is correct |
23 |
Correct |
53 ms |
6520 KB |
Output is correct |
24 |
Correct |
50 ms |
9544 KB |
Output is correct |
25 |
Correct |
52 ms |
7364 KB |
Output is correct |
26 |
Correct |
47 ms |
6920 KB |
Output is correct |
27 |
Correct |
26 ms |
8644 KB |
Output is correct |
28 |
Correct |
31 ms |
10252 KB |
Output is correct |
29 |
Correct |
52 ms |
12740 KB |
Output is correct |
30 |
Correct |
57 ms |
7316 KB |
Output is correct |