#include <bits/stdc++.h>
using namespace std;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define v vector
#define mp make_pair
typedef long long ll;
typedef pair<int, int > pii;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
void io() {
#ifdef LOCAL_PROJECT
freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else
#endif
ios_base::sync_with_stdio(false); cin.tie(NULL);
}
/***************************JOI16_skyscraper*************************************/
int N, a[100], L;
/*
# ways to assign [i,N] with total abs <= L
given start with g groups, e ends, sum base value
*/
ll f(int i, int g, int e, int sum) {
sum += (2 * g + e)*(a[i] - a[i - 1]);
if (sum > L) return 0;
if (i == N) {
if (g == 0 && e!=0) return 1;
else return 0;
}
ll ret = 0;
// join existing group
if (g > 0 || e > 0) ret += f(i + 1, g, e, sum)*(2 * g + e);
// make new group
ret += f(i + 1, g + 1, e, sum)*(g + 1);
// join two groups or ends
if (g > 0) ret += f(i + 1, g - 1, e, sum)*(e + g - 1);
// make new end, by itself
if (e < 2) ret += f(i + 1, g, e + 1, sum)*(2 - e);
// make new end, joined with a group
if (e < 2 && g>0) ret += f(i + 1, g - 1, e + 1, sum)*(2 - e);
ret %= 1000000007;
return ret;
}
int main() {
io();
cin >> N >> L;
if (N == 1) {
cout << 1 << "\n";
return 0;
}
FORE(i, 1, N) cin >> a[i];
sort(a + 1, a + 1 + N);
cout << f(1, 0, 0, 0) << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
16 ms |
300 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
14 ms |
256 KB |
Output is correct |
9 |
Correct |
36 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
16 ms |
300 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
14 ms |
256 KB |
Output is correct |
19 |
Correct |
36 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Execution timed out |
2056 ms |
384 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |