#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;
int dp[105][1005][3];
int dpp[105][1005][3];
int a[105];
int add(int a, int b){ a += b; if(a >= MOD) a -= MOD; return a; }
int mul(int a, int b){ return (1LL*a*b)%MOD; }
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, L;
cin >> n >> L;
for(int i=1; i<=n; i++) cin >> a[i];
sort(a+1, a+1+n);
if(n == 1){
cout << "1\n";
return 0;
}
if(2*(a[2]-a[1]) <= L) dp[1][2*(a[2]-a[1])][0] = 1;
if(a[2] - a[1] <= L) dp[1][a[2]-a[1]][1] = 2;
for(int i=2; i<=n; i++){
int dif = a[i+1] - a[i];
for(int j=1; j<=n; j++){
for(int zb=0; zb<=L; zb++){
for(int k=0; k<=2; k++){
dpp[j][zb][k] = dp[j][zb][k];
dp[j][zb][k] = 0;
}
}
}
for(int j=1; j<=n; j++){
for(int zb=0; zb<=L; zb++){
for(int k=0; k<=2; k++){
int val = dpp[j][zb][k];
/// povezujem 2 komponente
int posle = zb + dif*(2*j-k-2);
if(posle >= 0 && posle <= L) dp[j-1][posle][k] = add(dp[j-1][posle][k], mul(j-1, val));
/// uz jednu, ne stvaram endpoint
posle = zb + dif*(2*j-k);
if(posle >= 0 && posle <= L) dp[j][posle][k] = add(dp[j][posle][k], mul(2*j-k, val));
/// uz jednu, stvaram endpoint
posle = zb + dif*(2*j-k-1);
if(posle >= 0 && posle <= L && k < 2) dp[j][posle][k+1] = add(dp[j][posle][k+1], mul(2-k, val));
/// ni uz jednu, ne stvaram endpoint
posle = zb + dif*(2*j-k+2);
if(posle >= 0 && posle <= L) dp[j+1][posle][k] = add(dp[j+1][posle][k], mul(j+1-k, val));
/// ni uz jednu, stvaram endpoint
posle = zb + dif*(2*j-k+1);
if(posle >= 0 && posle <= L && k < 2) dp[j+1][posle][k+1] = add(dp[j+1][posle][k+1], mul(2-k, val));
}
}
}
}
int res = 0;
for(int i=0; i<=L; i++) res = add(res, dp[1][i][2]);
cout << res << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 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 |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
452 KB |
Output is correct |
8 |
Correct |
1 ms |
444 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 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 |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
452 KB |
Output is correct |
18 |
Correct |
1 ms |
444 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
588 KB |
Output is correct |
22 |
Correct |
251 ms |
2188 KB |
Output is correct |
23 |
Correct |
315 ms |
2688 KB |
Output is correct |
24 |
Correct |
269 ms |
2692 KB |
Output is correct |
25 |
Correct |
324 ms |
2636 KB |
Output is correct |
26 |
Correct |
281 ms |
2700 KB |
Output is correct |
27 |
Correct |
98 ms |
1684 KB |
Output is correct |
28 |
Correct |
129 ms |
1740 KB |
Output is correct |
29 |
Correct |
240 ms |
2380 KB |
Output is correct |
30 |
Correct |
327 ms |
2696 KB |
Output is correct |