#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100 +5;
const int M = 1000 +5;
const int mod = 1e9+7;
typedef pair<int,int> pii;
inline int add(int x, int y)
{
return (x+y>=mod ? x+y-mod : x+y);
}
inline int sub(int x, int y)
{
return (x-y<0 ? x-y+mod : x-y);
}
inline int gun(int x, int y)
{
return ((x*1ll*y)%mod);
}
int n,l;
int a[N];
int dp[N][M][M][3];
bool vis[N][M][M][3];
int solve(int idx, int comps, int sum, int matha)
{
if(sum > l)
return 0;
if(comps < 0 || comps >n)
return 0;
if(comps == 0 && idx>0)
return 0;
if(matha > 2)
return 0;
if(idx==n)
{
if(comps == 1 && matha == 2)
return 1;
return 0;
}
int &ret = dp[idx][comps][sum][matha];
if(vis[idx][comps][sum][matha])
return ret;
int prv = (idx-1>=0?a[idx-1] : 0);
int notun = sum + (a[idx]-prv)*(2*comps - matha);
int ans = 0;
//Create
ans = add(ans, gun(comps+1 - matha, solve(idx+1, comps+1, notun, matha)));
//merge
if(comps >= 2)
ans = add(ans, gun(comps-1, solve(idx+1, comps-1, notun, matha)) );
//add
if(comps>=1)
ans = add(ans, gun(2*comps-matha, solve(idx+1, comps, notun, matha)));
//notun matha
ans = add(ans, gun(2-matha, solve(idx+1, comps+1, notun, matha+1)));
//mathay lagao
ans = add(ans, gun(2-matha, solve(idx+1, comps, notun, matha+1)));
return ret = ans;
}
int32_t main()
{
cin>>n>>l;
for(int i=0; i<n; i++)
{
cin>>a[i];
}
sort(a,a+n);
if(n==1)
{
cout<<"1\n";
return 0;
}
cout<<solve(0,0,0,0)<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
576 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
692 KB |
Output is correct |
2 |
Correct |
4 ms |
596 KB |
Output is correct |
3 |
Correct |
79 ms |
796 KB |
Output is correct |
4 |
Correct |
4 ms |
596 KB |
Output is correct |
5 |
Correct |
4 ms |
596 KB |
Output is correct |
6 |
Correct |
23 ms |
716 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
68 ms |
664 KB |
Output is correct |
9 |
Correct |
177 ms |
696 KB |
Output is correct |
10 |
Correct |
5 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
576 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
31 ms |
692 KB |
Output is correct |
12 |
Correct |
4 ms |
596 KB |
Output is correct |
13 |
Correct |
79 ms |
796 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
23 ms |
716 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
68 ms |
664 KB |
Output is correct |
19 |
Correct |
177 ms |
696 KB |
Output is correct |
20 |
Correct |
5 ms |
596 KB |
Output is correct |
21 |
Execution timed out |
2083 ms |
1332 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |