#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast,unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")*/
//#pragma GCC optimize("O2")
/*#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")*/
using namespace std;
using ll = long long int;
using ld = long double;
#define F first
#define S second
#define pb push_back
//#define mp make_pair
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int N=1e2+10,LN=20,M=3.5e7+10,SQ=350,BS=737,inf=1e9+10;
const ll INF=1e15;
const ld ep=1e-7;
const int MH=1000696969,MOD=1000000007,MD=998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
ll ans=1;
while (y != 0) {
if (y & 1) ans = ans * x % mod;
y >>= 1;
x = x * x % mod;
}
return ans;
}
ll n,k,a[N],dp[N][N][1005][3],ans;
int main(){
fast_io;
cin >> n >> k;
if(n==1) return cout << 1 << '\n', 0;
for(ll i=1; i<=n; i++){
cin >> a[i];
}
dp[0][0][0][0]=1;
sort(a+1,a+n+1);
for(ll i=1; i<=n; i++){
for(ll j=1; j<=i; j++){
for(ll x=0; x<=k; x++){
for(ll y=0; y<3; y++){
ll c=(2*j-y)*(a[i+1]-a[i]);
if(c>x || i+j-y>=n) continue;
dp[i][j][x][y]+=dp[i-1][j-1][x-c][y]+(2*j-y)*dp[i-1][j][x-c][y];
if(y) dp[i][j][x][y]+=(3^y)*dp[i-1][j-1][x-c][y-1];
if(y==1){
dp[i][j][x][y]+=2*j*dp[i-1][j][x-c][y-1]+j*j*dp[i-1][j+1][x-c][y];
}else if(y==2){
if(i==n) dp[i][j][x][y]+=dp[i-1][j+1][x-c][y]+dp[i-1][j][x-c][y-1];
else dp[i][j][x][y]+=(j-1)*dp[i-1][j][x-c][y-1]+j*(j-1)*dp[i-1][j+1][x-c][y];
}else{
dp[i][j][x][y]+=j*(j+1)*dp[i-1][j+1][x-c][y];
}
dp[i][j][x][y]%=MOD;
}
}
}
}
for(ll i=0; i<=k; i++) ans+=dp[n][1][i][2];
cout << ans%MOD << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
452 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
452 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
716 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
2 ms |
2380 KB |
Output is correct |
22 |
Correct |
66 ms |
35916 KB |
Output is correct |
23 |
Correct |
90 ms |
47612 KB |
Output is correct |
24 |
Correct |
84 ms |
46760 KB |
Output is correct |
25 |
Correct |
93 ms |
50616 KB |
Output is correct |
26 |
Correct |
90 ms |
46136 KB |
Output is correct |
27 |
Correct |
37 ms |
23604 KB |
Output is correct |
28 |
Correct |
41 ms |
26924 KB |
Output is correct |
29 |
Correct |
67 ms |
41284 KB |
Output is correct |
30 |
Correct |
98 ms |
50896 KB |
Output is correct |