#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
return uniform_int_distribution<ll>(l,r)(rng);
}
#define maxn 105
ll n,L;
ll a[maxn];
map<ll,ll> dp[maxn][maxn][2][2];
int main(){
daj_mi_malo_vremena
cin >> n >> L;
for(ll i = 1;i<=n;i++) cin >> a[i];
if(n==1){cout<<1<<endl;return 0;}
sort(a+1,a+n+1);
dp[1][1][1][0][-a[1]] = 1;
dp[1][1][0][1][-a[1]] = 1;
dp[1][1][0][0][-2*a[1]] = 1;
for(ll i = 2;i<=n;i++){
for(ll j = 1;j<=i;j++){
for(ll l = 0;l<=1;l++){
for(ll r = 0;r<=1;r++){
for(pll p : dp[i-1][j][l][r]){
ll k = p.fi;
ll cnt = p.sc;
if(k>L||k + (2*j-l-r)*a[i]>L) break;
dp[i][j][l][r][k] = add(dp[i][j][l][r][k],mul(cnt,2*j-l-r));
if(!l) dp[i][j][1][r][k+a[i]] = add(dp[i][j][1][r][k+a[i]],cnt);
if(!r) dp[i][j][l][1][k+a[i]] = add(dp[i][j][l][1][k+a[i]],cnt);
dp[i][j+1][l][r][k-2*a[i]] = add(dp[i][j+1][l][r][k-2*a[i]],mul(cnt,j+1-l-r));
if(!l) dp[i][j+1][1][r][k-a[i]] = add(dp[i][j+1][1][r][k-a[i]],cnt);
if(!r) dp[i][j+1][l][1][k-a[i]] = add(dp[i][j+1][l][1][k-a[i]],cnt);
dp[i][j-1][l][r][k+2*a[i]] = add(dp[i][j-1][l][r][k+2*a[i]],mul(cnt,j-1));
}
}
}
}
}
ll ans = 0;
for(pll p : dp[n][1][1][1]){
ll k = p.fi;
ll cnt = p.sc;
if(k<=L) ans = add(ans,cnt);
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2388 KB |
Output is correct |
2 |
Correct |
1 ms |
2388 KB |
Output is correct |
3 |
Correct |
1 ms |
2388 KB |
Output is correct |
4 |
Correct |
1 ms |
2388 KB |
Output is correct |
5 |
Correct |
1 ms |
2388 KB |
Output is correct |
6 |
Correct |
2 ms |
2516 KB |
Output is correct |
7 |
Correct |
2 ms |
2388 KB |
Output is correct |
8 |
Correct |
2 ms |
2516 KB |
Output is correct |
9 |
Correct |
2 ms |
2516 KB |
Output is correct |
10 |
Correct |
2 ms |
2516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2772 KB |
Output is correct |
2 |
Correct |
3 ms |
2772 KB |
Output is correct |
3 |
Correct |
3 ms |
2756 KB |
Output is correct |
4 |
Correct |
3 ms |
2772 KB |
Output is correct |
5 |
Correct |
3 ms |
2772 KB |
Output is correct |
6 |
Correct |
4 ms |
2956 KB |
Output is correct |
7 |
Correct |
2 ms |
2516 KB |
Output is correct |
8 |
Correct |
3 ms |
2772 KB |
Output is correct |
9 |
Correct |
4 ms |
2980 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2388 KB |
Output is correct |
2 |
Correct |
1 ms |
2388 KB |
Output is correct |
3 |
Correct |
1 ms |
2388 KB |
Output is correct |
4 |
Correct |
1 ms |
2388 KB |
Output is correct |
5 |
Correct |
1 ms |
2388 KB |
Output is correct |
6 |
Correct |
2 ms |
2516 KB |
Output is correct |
7 |
Correct |
2 ms |
2388 KB |
Output is correct |
8 |
Correct |
2 ms |
2516 KB |
Output is correct |
9 |
Correct |
2 ms |
2516 KB |
Output is correct |
10 |
Correct |
2 ms |
2516 KB |
Output is correct |
11 |
Correct |
3 ms |
2772 KB |
Output is correct |
12 |
Correct |
3 ms |
2772 KB |
Output is correct |
13 |
Correct |
3 ms |
2756 KB |
Output is correct |
14 |
Correct |
3 ms |
2772 KB |
Output is correct |
15 |
Correct |
3 ms |
2772 KB |
Output is correct |
16 |
Correct |
4 ms |
2956 KB |
Output is correct |
17 |
Correct |
2 ms |
2516 KB |
Output is correct |
18 |
Correct |
3 ms |
2772 KB |
Output is correct |
19 |
Correct |
4 ms |
2980 KB |
Output is correct |
20 |
Correct |
3 ms |
2772 KB |
Output is correct |
21 |
Correct |
5 ms |
3284 KB |
Output is correct |
22 |
Correct |
1317 ms |
176624 KB |
Output is correct |
23 |
Correct |
472 ms |
85044 KB |
Output is correct |
24 |
Correct |
613 ms |
98400 KB |
Output is correct |
25 |
Correct |
542 ms |
93328 KB |
Output is correct |
26 |
Correct |
472 ms |
80628 KB |
Output is correct |
27 |
Correct |
280 ms |
45708 KB |
Output is correct |
28 |
Correct |
405 ms |
62476 KB |
Output is correct |
29 |
Correct |
783 ms |
114880 KB |
Output is correct |
30 |
Correct |
530 ms |
92120 KB |
Output is correct |