This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// YOt ONLY GOT ONE SHOT
#include <bits/stdc++.h>
#define put(x) cerr << #x << ": " << x << '\n'
#define line() cerr << "**************\n"
//#define F first
//#define S second
//#define mul(x, y) (((x) * (y)) %mod)
//#define bit(i, j) (((i)>>(j)) &1)
//#define left(id) ((id<<1) + 1)
//#define right(id) ((id<<1) + 2)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
const int maxn = 100 + 10, maxA = 1000 + 10, mod = 1e9 + 7;
int n, l;
int a[maxn];
int dp[maxn][maxn][maxA][3];
ll mul(ll a, ll b){
return (a * b) %mod;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> l;
for(int i=0; i<n; i++)
cin >> a[i];
sort(a, a+n);
if(n == 1)
return cout << "1\n", 0;
for(int i=0; i<=l; i++)
dp[0][0][i][0] = 1;
int cost = 0;
for(int i=1; i<=n; i++)
for(int j = 1; j <= min(i, (n+1) /2); j++)
for(int k=0; k<=l; k++)
for(int m=0; m<3; m++){
cost = (j * 2 - m) * (a[i] - a[i-1]);
if(cost > k)
continue;
if(m > 0){
dp[i][j][k][m] += mul(dp[i-1][j][k - cost][m-1], 3 - m);
dp[i][j][k][m] %= mod;
if(i + j + 1 - m <= n){
dp[i][j][k][m] += mul(dp[i-1][j-1][k - cost][m-1], 3 - m);
dp[i][j][k][m] %= mod;
}
}
if(i + j +1 - m <= n){
dp[i][j][k][m] += mul(dp[i-1][j-1][k - cost][m], j - m);
dp[i][j][k][m] %= mod;
dp[i][j][k][m] += mul(dp[i-1][j][k - cost][m], j * 2 - m);
dp[i][j][k][m] %= mod;
}
if(j < (n + 1) /2){
dp[i][j][k][m] += mul(dp[i-1][j+1][k - cost][m], j) %mod;
dp[i][j][k][m] %= mod;
}
}
cout << dp[n][1][l][2] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |