#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <cassert>
#include <algorithm>
#define rep(i,n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
#define INF 1145141919
#define MOD 1000000007
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }
int N, L;
int A[100];
//#define MAX_L 2800
#define MAX_L 1200
int dp[2][1<<14][MAX_L+1];
int main() {
cin >> N >> L;
if (N > 14) abort();
rep(i, N) cin >> A[i];
sort(A, A+N, greater<int>());
int lo = A[N-1], hi = A[0];
if (hi-lo > L) {
cout << 0 << "\n";
return 0;
}
rep(i, N) A[i] -= lo;
dp[0][0][0] = 1;
rep(i, N) {
rep(j, 1<<N) rep(k, MAX_L+1) dp[1][j][k] = 0;
rep(S, 1<<N) {
rep(pos, N) {
if ((S>>pos)&1) continue;
int left = 0, right = 0;
if (pos > 0) left = ((S>>(pos-1))&1) ? -1 : 1;
if (pos+1 < N) right = ((S>>(pos+1))&1) ? -1 : 1;
int e = A[i]*(left+right);
int nS = S|(1<<pos);
for (int k=max(-e, 0); k+e<=MAX_L; k++) {
add(dp[1][nS][k+e], dp[0][S][k]);
}
}
}
swap(dp[0], dp[1]);
}
int s = 0;
rep(i, L+1) add(s, dp[0][(1<<N)-1][i]);
cout << s << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
155744 KB |
Output is correct |
2 |
Correct |
63 ms |
155744 KB |
Output is correct |
3 |
Correct |
113 ms |
155744 KB |
Output is correct |
4 |
Correct |
236 ms |
155744 KB |
Output is correct |
5 |
Correct |
273 ms |
155744 KB |
Output is correct |
6 |
Correct |
299 ms |
155744 KB |
Output is correct |
7 |
Correct |
0 ms |
155744 KB |
Output is correct |
8 |
Correct |
323 ms |
155744 KB |
Output is correct |
9 |
Incorrect |
286 ms |
155744 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1149 ms |
155744 KB |
Output is correct |
2 |
Execution timed out |
2000 ms |
155744 KB |
Execution timed out |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
155744 KB |
Output is correct |
2 |
Correct |
63 ms |
155744 KB |
Output is correct |
3 |
Correct |
113 ms |
155744 KB |
Output is correct |
4 |
Correct |
236 ms |
155744 KB |
Output is correct |
5 |
Correct |
273 ms |
155744 KB |
Output is correct |
6 |
Correct |
299 ms |
155744 KB |
Output is correct |
7 |
Correct |
0 ms |
155744 KB |
Output is correct |
8 |
Correct |
323 ms |
155744 KB |
Output is correct |
9 |
Incorrect |
286 ms |
155744 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |