#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1<<14, inf = LLONG_MAX/2;
int dp[15][101][N];
vector<int> a;
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,L;
cin >> n >> L;
a = vector<int>(n+1);
for (int i=1; i<=n; ++i){
cin >> a[i];
}
fill_n(&dp[0][0][0],15*N*101,0);
dp[0][0][0] = 1;
for (int mask=0; mask<(1<<n); ++mask){
for (int sum=0; sum<=L; ++sum){
for (int last=0; last<=n; ++last){
if (last != 0 and !(mask&(1<<(last-1)))) continue;
for (int unused=1; unused<=n; ++unused){
if (unused == last or !(mask&(1<<(unused-1)))) continue;
int sum2 = sum;
if (last != 0) sum2 += abs(a[unused]-a[last]);
if (sum2 <= L)
dp[unused][sum2][mask] += dp[last][sum][mask-(1<<(unused-1))];
}
}
}
}
int ans = 0;
for (int k=0; k<=n; ++k){
for (int j=0; j<=L; ++j){
ans += dp[k][j][(1<<n)-1];
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
194568 KB |
Output is correct |
2 |
Correct |
32 ms |
194640 KB |
Output is correct |
3 |
Correct |
29 ms |
194644 KB |
Output is correct |
4 |
Correct |
27 ms |
194728 KB |
Output is correct |
5 |
Runtime error |
223 ms |
394524 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
194640 KB |
Output is correct |
2 |
Correct |
1241 ms |
194728 KB |
Output is correct |
3 |
Correct |
461 ms |
194640 KB |
Output is correct |
4 |
Correct |
1303 ms |
194732 KB |
Output is correct |
5 |
Correct |
1284 ms |
194728 KB |
Output is correct |
6 |
Correct |
1363 ms |
194896 KB |
Output is correct |
7 |
Correct |
290 ms |
194732 KB |
Output is correct |
8 |
Correct |
453 ms |
194728 KB |
Output is correct |
9 |
Incorrect |
941 ms |
194728 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
194568 KB |
Output is correct |
2 |
Correct |
32 ms |
194640 KB |
Output is correct |
3 |
Correct |
29 ms |
194644 KB |
Output is correct |
4 |
Correct |
27 ms |
194728 KB |
Output is correct |
5 |
Runtime error |
223 ms |
394524 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |