This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e2 + 5;
const int MAXM = 1e3 + 5;
const ll INF = 1e18 + 5;
const int MOD = 1e9 + 7;
int n, l, a[MAXN];
void Input()
{
cin >> n >> l;
for (int i = 1; i <= n; i++)
cin >> a[i];
}
int mul(int a, int b)
{
return 1ll * a * b % MOD;
}
void add(int& a, int b)
{
a += b;
if (a > MOD)
a -= MOD;
}
int dp[MAXN][MAXN][MAXM][3];
void Solve()
{
sort (a + 1, a + n + 1);
dp[1][1][0][0] = dp[1][1][0][2] = 1;
dp[1][1][0][1] = 2;
for (int i = 1; i < n; i++)
{
for (int j = 1; j <= i; j++)
{
for (int k = 0; k <= l; k++)
{
for (int z = 0; z <= 2; z++)
{
int nk = k + (2 * j - z) * (a[i + 1] - a[i]);
if (!dp[i][j][k][z] || nk < 0 || nk > l)
continue;
add(dp[i + 1][j + 1][nk][z], mul(dp[i][j][k][z], j + 1 - z));
add(dp[i + 1][j][nk][z], mul(dp[i][j][k][z], 2 * j - z));
if (j >= 2)
add(dp[i + 1][j - 1][nk][z], mul(dp[i][j][k][z], j - 1));
if (z < 2)
{
add(dp[i + 1][j][nk][z + 1], mul(dp[i][j][k][z], 2 - z));
add(dp[i + 1][j + 1][nk][z + 1], mul(dp[i][j][k][z], 2 - z));
}
}
}
}
}
int ans = 0;
for (int i = 0; i <= l; i++)
add(ans, dp[n][1][i][2]);
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".INP","r"))
{
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
Input();
Solve();
}
Compilation message (stderr)
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |