#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
int sum(int a, int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
void sumi(int &a, int b) {
a = sum(a, b);
}
int sub(int a, int b) {
return a - b < 0 ? a - b + MOD : a - b;
}
int mul(int a, int b) {
return (1LL*a*b)%MOD;
}
const int MAXN = 103, MAXL = 1003;
int ar[MAXN];
int dp[MAXN][MAXN][2][2][MAXL];
int n, l;
int solve(int ps, int open, int bam, int dan, int x) {
if (x > l) return 0;
assert(x >= 0);
if (ps == n) {
if (open == 1) return bam ^ dan;
if (open == 2) return bam & dan;
return 0;
}
int &ans = dp[ps][open][bam][dan][x];
if (ans != -1) return ans;
ans = 0;
int y = open*2-bam-dan;
int z = ar[ps+1]-ar[ps];
///single comp inside
sumi(ans, solve(ps+1, open+1, bam, dan, x+y*z+2*z));
///single comp border
if (!bam) sumi(ans, solve(ps+1, open+1, 1, dan, x+y*z+z));
if (!dan) sumi(ans, solve(ps+1, open+1, bam, 1, x+y*z+z));
///extend one side of a comp inside
if (open > 0) sumi(ans, mul(open*2-bam-dan, solve(ps+1, open, bam, dan, x+y*z)));
///extend one side of a comp border
if (!bam && open > dan) sumi(ans, mul(open-dan, solve(ps+1, open, 1, dan, x+y*z-z)));
if (!dan && open > bam) sumi(ans, mul(open-bam, solve(ps+1, open, bam, 1, x+y*z-z)));
///glue two comps
if (open >= 2) {
int ways = (open-dan)*(open-bam)-bam*dan-(open-bam-dan);
if (ways > 0) sumi(ans, mul(ways, solve(ps+1, open-1, bam, dan, x+y*z-2*z)));
}
return ans;
}
int main() {
cin >> n >> l;
for (int i = 1; i <= n; i++) cin >> ar[i];
sort(ar+1, ar+n+1);
///handle n == 1
if (n == 1) {
cout << 1 << endl;
return 0;
}
memset(dp, -1, sizeof dp);
cout << solve(1, 0, 0, 0, 0) << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
82 ms |
166912 KB |
Output is correct |
3 |
Correct |
85 ms |
166860 KB |
Output is correct |
4 |
Correct |
81 ms |
166892 KB |
Output is correct |
5 |
Correct |
83 ms |
166892 KB |
Output is correct |
6 |
Correct |
82 ms |
166892 KB |
Output is correct |
7 |
Correct |
81 ms |
166892 KB |
Output is correct |
8 |
Correct |
83 ms |
166892 KB |
Output is correct |
9 |
Correct |
83 ms |
166892 KB |
Output is correct |
10 |
Correct |
81 ms |
167020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
167020 KB |
Output is correct |
2 |
Correct |
82 ms |
166892 KB |
Output is correct |
3 |
Correct |
82 ms |
166892 KB |
Output is correct |
4 |
Correct |
83 ms |
166892 KB |
Output is correct |
5 |
Correct |
84 ms |
166892 KB |
Output is correct |
6 |
Correct |
83 ms |
166892 KB |
Output is correct |
7 |
Correct |
83 ms |
166892 KB |
Output is correct |
8 |
Correct |
84 ms |
167020 KB |
Output is correct |
9 |
Correct |
90 ms |
167020 KB |
Output is correct |
10 |
Correct |
84 ms |
167040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
82 ms |
166912 KB |
Output is correct |
3 |
Correct |
85 ms |
166860 KB |
Output is correct |
4 |
Correct |
81 ms |
166892 KB |
Output is correct |
5 |
Correct |
83 ms |
166892 KB |
Output is correct |
6 |
Correct |
82 ms |
166892 KB |
Output is correct |
7 |
Correct |
81 ms |
166892 KB |
Output is correct |
8 |
Correct |
83 ms |
166892 KB |
Output is correct |
9 |
Correct |
83 ms |
166892 KB |
Output is correct |
10 |
Correct |
81 ms |
167020 KB |
Output is correct |
11 |
Correct |
82 ms |
167020 KB |
Output is correct |
12 |
Correct |
82 ms |
166892 KB |
Output is correct |
13 |
Correct |
82 ms |
166892 KB |
Output is correct |
14 |
Correct |
83 ms |
166892 KB |
Output is correct |
15 |
Correct |
84 ms |
166892 KB |
Output is correct |
16 |
Correct |
83 ms |
166892 KB |
Output is correct |
17 |
Correct |
83 ms |
166892 KB |
Output is correct |
18 |
Correct |
84 ms |
167020 KB |
Output is correct |
19 |
Correct |
90 ms |
167020 KB |
Output is correct |
20 |
Correct |
84 ms |
167040 KB |
Output is correct |
21 |
Correct |
82 ms |
166892 KB |
Output is correct |
22 |
Correct |
358 ms |
166892 KB |
Output is correct |
23 |
Correct |
118 ms |
167020 KB |
Output is correct |
24 |
Correct |
152 ms |
166892 KB |
Output is correct |
25 |
Correct |
129 ms |
166892 KB |
Output is correct |
26 |
Correct |
125 ms |
166892 KB |
Output is correct |
27 |
Correct |
129 ms |
166892 KB |
Output is correct |
28 |
Correct |
155 ms |
166892 KB |
Output is correct |
29 |
Correct |
215 ms |
166892 KB |
Output is correct |
30 |
Correct |
125 ms |
167076 KB |
Output is correct |