#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
#define left sefude
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
if(b==0LL) return 1LL;
if(b==1LL) return mod(a,m);
ll k = mod(exp(a,b/2,m),m);
if(b&1LL){
return mod(a*mod(k*k,m),m);
}
else return mod(k*k,m);
}
const int N = 103;
const int M = 1e9 + 7;
ll dp[N][1010][N][2][2];
int a[N];
int n,L;
ll solve(int i,int l,int k,int kl,int kr){
// tem k componentes, kl-> se tem algum no left , kr ->tem no right
if(k < 0)return 0;
if(i)l+= (a[i] - a[i-1])*(2*k + kl + kr);
if(l > L)return 0;
if(i == n - 1){
return !k;
}
ll &x = dp[i][l][k][kl][kr];
if(x!=-1)return x;
x=0;
// create to left:
// append to left
x += solve(i+1,l,k,1,kr);
// append + merge
x += solve(i+1,l,k-1,1,kr) * k;
// create to right:
// append only
x += solve(i+1,l,k,kl,1);
// append + merge
x += solve(i+1,l,k-1,kl,1) * k;
// now the middle stuff
// isolado
x += solve(i+1,l,k+1,kl,kr);
// merge with one ( to the left/right of it)
x += 2ll*k*solve(i+1,l,k,kl,kr);
// merge two boys
x += 1ll * k * (k-1) * solve(i+1,l,k-1,kl,kr);
x%=M;
return x;
}
int32_t main(){
fastio;
cin >> n >> L;
for(int i=0;i<n;i++){
cin >> a[i];
}
sort(a,a+n);
ms(dp,-1);
cout << solve(0,0,0,0,0) << endl;
// math -> gcd it all
// Did u check N=1? Did you switch N,M?
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
169 ms |
335864 KB |
Output is correct |
2 |
Correct |
182 ms |
335864 KB |
Output is correct |
3 |
Correct |
164 ms |
335864 KB |
Output is correct |
4 |
Correct |
169 ms |
335864 KB |
Output is correct |
5 |
Correct |
167 ms |
335864 KB |
Output is correct |
6 |
Correct |
172 ms |
335864 KB |
Output is correct |
7 |
Correct |
178 ms |
336004 KB |
Output is correct |
8 |
Correct |
177 ms |
335864 KB |
Output is correct |
9 |
Correct |
164 ms |
335864 KB |
Output is correct |
10 |
Correct |
167 ms |
335864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
169 ms |
335864 KB |
Output is correct |
2 |
Correct |
171 ms |
335740 KB |
Output is correct |
3 |
Correct |
179 ms |
335736 KB |
Output is correct |
4 |
Correct |
174 ms |
335864 KB |
Output is correct |
5 |
Correct |
174 ms |
335864 KB |
Output is correct |
6 |
Correct |
172 ms |
335864 KB |
Output is correct |
7 |
Correct |
167 ms |
335864 KB |
Output is correct |
8 |
Correct |
167 ms |
335816 KB |
Output is correct |
9 |
Correct |
170 ms |
335864 KB |
Output is correct |
10 |
Correct |
173 ms |
335864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
169 ms |
335864 KB |
Output is correct |
2 |
Correct |
182 ms |
335864 KB |
Output is correct |
3 |
Correct |
164 ms |
335864 KB |
Output is correct |
4 |
Correct |
169 ms |
335864 KB |
Output is correct |
5 |
Correct |
167 ms |
335864 KB |
Output is correct |
6 |
Correct |
172 ms |
335864 KB |
Output is correct |
7 |
Correct |
178 ms |
336004 KB |
Output is correct |
8 |
Correct |
177 ms |
335864 KB |
Output is correct |
9 |
Correct |
164 ms |
335864 KB |
Output is correct |
10 |
Correct |
167 ms |
335864 KB |
Output is correct |
11 |
Correct |
169 ms |
335864 KB |
Output is correct |
12 |
Correct |
171 ms |
335740 KB |
Output is correct |
13 |
Correct |
179 ms |
335736 KB |
Output is correct |
14 |
Correct |
174 ms |
335864 KB |
Output is correct |
15 |
Correct |
174 ms |
335864 KB |
Output is correct |
16 |
Correct |
172 ms |
335864 KB |
Output is correct |
17 |
Correct |
167 ms |
335864 KB |
Output is correct |
18 |
Correct |
167 ms |
335816 KB |
Output is correct |
19 |
Correct |
170 ms |
335864 KB |
Output is correct |
20 |
Correct |
173 ms |
335864 KB |
Output is correct |
21 |
Correct |
176 ms |
335868 KB |
Output is correct |
22 |
Correct |
489 ms |
335808 KB |
Output is correct |
23 |
Correct |
410 ms |
335864 KB |
Output is correct |
24 |
Correct |
412 ms |
335864 KB |
Output is correct |
25 |
Correct |
396 ms |
335892 KB |
Output is correct |
26 |
Correct |
346 ms |
335944 KB |
Output is correct |
27 |
Correct |
228 ms |
335864 KB |
Output is correct |
28 |
Correct |
256 ms |
335992 KB |
Output is correct |
29 |
Correct |
384 ms |
335992 KB |
Output is correct |
30 |
Correct |
403 ms |
335884 KB |
Output is correct |