#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;
// if (x < 0) {
// cout << "[" << ps << "][" << open << "][" << bam << "][" << dan << "][" << x << "]" << endl;
// }
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];
// vector< string >vs;
// int b4 = 0;
///single comp inside
sumi(ans, solve(ps+1, open+1, bam, dan, x+y*z+2*z));
// if (ans != b4) {
// vs.push_back("single comp inside");
// b4 = ans;
// }
///single comp border
if (!bam) sumi(ans, solve(ps+1, open+1, 1, dan, x+y*z+z));
// if (ans != b4) {
// vs.push_back("single comp border bam");
// b4 = ans;
// }
if (!dan) sumi(ans, solve(ps+1, open+1, bam, 1, x+y*z+z));
// if (ans != b4) {
// vs.push_back("single comp border dan");
// b4 = ans;
// }
///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)));
// if (ans != b4) {
// vs.push_back("extend one side of a comp inside");
// b4 = ans;
// }
///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 (ans != b4) {
// vs.push_back("extend one side of a comp border bam");
// b4 = ans;
// }
if (!dan && open > bam) sumi(ans, mul(open-bam, solve(ps+1, open, bam, 1, x+y*z-z)));
// if (ans != b4) {
// vs.push_back("extend one side of a comp border dan");
// b4 = ans;
// }
///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)));
}
// if (ans != b4) {
// vs.push_back("glue two comps");
// b4 = ans;
// }
// for (string s : vs) cout << s << " | ";
// cout << endl;
// cout << "dp[" << ps << "][" << open << "][" << bam << "][" << dan << "][" << x << "] = " << ans << endl;
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
81 ms |
166912 KB |
Output is correct |
3 |
Correct |
81 ms |
166892 KB |
Output is correct |
4 |
Correct |
82 ms |
167020 KB |
Output is correct |
5 |
Correct |
83 ms |
166892 KB |
Output is correct |
6 |
Correct |
82 ms |
166892 KB |
Output is correct |
7 |
Correct |
82 ms |
167020 KB |
Output is correct |
8 |
Correct |
83 ms |
166892 KB |
Output is correct |
9 |
Correct |
86 ms |
166892 KB |
Output is correct |
10 |
Correct |
85 ms |
167020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
166892 KB |
Output is correct |
2 |
Correct |
85 ms |
166892 KB |
Output is correct |
3 |
Correct |
83 ms |
166892 KB |
Output is correct |
4 |
Correct |
83 ms |
166892 KB |
Output is correct |
5 |
Correct |
86 ms |
167020 KB |
Output is correct |
6 |
Correct |
84 ms |
166944 KB |
Output is correct |
7 |
Correct |
82 ms |
166892 KB |
Output is correct |
8 |
Correct |
83 ms |
166892 KB |
Output is correct |
9 |
Correct |
83 ms |
167020 KB |
Output is correct |
10 |
Correct |
82 ms |
167020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
81 ms |
166912 KB |
Output is correct |
3 |
Correct |
81 ms |
166892 KB |
Output is correct |
4 |
Correct |
82 ms |
167020 KB |
Output is correct |
5 |
Correct |
83 ms |
166892 KB |
Output is correct |
6 |
Correct |
82 ms |
166892 KB |
Output is correct |
7 |
Correct |
82 ms |
167020 KB |
Output is correct |
8 |
Correct |
83 ms |
166892 KB |
Output is correct |
9 |
Correct |
86 ms |
166892 KB |
Output is correct |
10 |
Correct |
85 ms |
167020 KB |
Output is correct |
11 |
Correct |
84 ms |
166892 KB |
Output is correct |
12 |
Correct |
85 ms |
166892 KB |
Output is correct |
13 |
Correct |
83 ms |
166892 KB |
Output is correct |
14 |
Correct |
83 ms |
166892 KB |
Output is correct |
15 |
Correct |
86 ms |
167020 KB |
Output is correct |
16 |
Correct |
84 ms |
166944 KB |
Output is correct |
17 |
Correct |
82 ms |
166892 KB |
Output is correct |
18 |
Correct |
83 ms |
166892 KB |
Output is correct |
19 |
Correct |
83 ms |
167020 KB |
Output is correct |
20 |
Correct |
82 ms |
167020 KB |
Output is correct |
21 |
Correct |
83 ms |
166892 KB |
Output is correct |
22 |
Correct |
339 ms |
166892 KB |
Output is correct |
23 |
Correct |
118 ms |
166892 KB |
Output is correct |
24 |
Correct |
151 ms |
166892 KB |
Output is correct |
25 |
Correct |
131 ms |
167068 KB |
Output is correct |
26 |
Correct |
123 ms |
167040 KB |
Output is correct |
27 |
Correct |
130 ms |
166892 KB |
Output is correct |
28 |
Correct |
157 ms |
166892 KB |
Output is correct |
29 |
Correct |
223 ms |
167020 KB |
Output is correct |
30 |
Correct |
129 ms |
167020 KB |
Output is correct |