# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1043799 | lozergam | Skyscraper (JOI16_skyscraper) | C++17 | 49 ms | 51024 KiB |
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>
using namespace std;
#define ll long long
#define pb push_back
#define For(i, n) for(int (i) = 0 ; (i) < (n); (i)++)
#define debug(x) cout << #x << " : " << x << endl << flush
#define endl '\n'
#define sz(x) (ll)x.size()
const ll MOD = 1e9 + 7;
const ll maxn = 103;
const ll maxl = 1005;
ll dp[maxn][maxn][maxl][3];
ll a[maxn];
ll n, l;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> n >> l;
for(int i = 1; i <= n; i++)
cin >> a[i];
if(n == 1)
{
cout << 1 << endl;
exit(0);
}
sort(a + 1, a + n + 1);
a[n + 1] = 10000;
dp[0][0][0][0] = 1;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= i; j++)
for(int k = 0; k <= l; k++)
for(int m = 0; m <= 2; m++)
{
ll delta = (2 * j - m) * (a[i + 1] - a[i]);
if(delta > k)continue;
if(i + j + 1 - m > n)continue;
//new element make a new comp and dont have end point
dp[i][j][k][m] += dp[i - 1][j - 1][k - delta][m];
//new element make a new comp and have end point
if(m == 1)
dp[i][j][k][m] += 2 * dp[i - 1][j - 1][k - delta][0];
else if(m == 2)
dp[i][j][k][m] += dp[i - 1][j - 1][k - delta][1];
//new element go to one of the comps but not the endpoint
dp[i][j][k][m] += (2 * j - m) * dp[i - 1][j][k - delta][m];
//new element go to one of the comps and endpoint
if(m == 1)
dp[i][j][k][m] += (2 * j) * dp[i - 1][j][k - delta][0];
else if(m == 2 and i == n)
dp[i][j][k][m] += dp[i - 1][j][k - delta][1];
else if(m == 2)
dp[i][j][k][m] += (j - 1) * dp[i - 1][j][k - delta][1];
//new element combone two comps
if(m == 0)
dp[i][j][k][m] += (j * (j + 1)) * dp[i - 1][j + 1][k - delta][0];
else if(m == 1)
dp[i][j][k][m] += (j * (j - 1) + j) * dp[i - 1][j + 1][k - delta][1];
else if(i == n)
dp[i][j][k][m] += dp[i - 1][j + 1][k - delta][2];
else
dp[i][j][k][m] += ((2 * (j - 1)) + ((j - 1) * (j - 2))) * dp[i - 1][j + 1][k - delta][2];
dp[i][j][k][m] %= MOD;
}
ll ans = 0;
For(i, l+1)ans += dp[n][1][i][2];
cout << ans % MOD << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |