/*
JOIOC 16-skyscraper
*/
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
// #define fisier 1
using namespace std;
typedef long long ll;
int add(int a, int b)
{
int x = a+b;
if(x >= mod)
x -= mod;
if(x < 0)
x += mod;
return x;
}
ll mul(ll a, ll b)
{
return (a*b) % mod;
}
int n, maxsum;
ll v[102];
ll dp[102][102][1002][3];
/*
dp[i][j][k][l]:
i - number of numbers placed
j - number of connected components
k - total sum currently (filling empty spaces with a_{i} (0-indexed)
l - number of endpoints that are filled
*/
int solve(int i, int j, int k, int l)
{
if(i > 0 && (j < 1 || l > 2 || k > maxsum)) // invalid conditions
return 0;
if(i == n)
return (j == 1 && l == 2);
if(dp[i][j][k][l] != -1)
return dp[i][j][k][l];
int s = (v[i + 1] - v[i]) * (2 * j - l) + k;
dp[i][j][k][l] = 0;
add(dp[i][j][k][l], mul((j + 1 - l), solve(i + 1, j + 1, s, l)));
add(dp[i][j][k][l], mul((2 - l), solve(i + 1, j, s, l + 1)));
add(dp[i][j][k][l], mul((2 - l), solve(i + 1, j + 1, s, l + 1)));
add(dp[i][j][k][l], mul((j - 1), solve(i + 1, j - 1, s, l)));
add(dp[i][j][k][l], mul((2 * j - l), solve(i + 1, j, s, l)));
return dp[i][j][k][l];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> maxsum;
for(int i = 1; i <= n; i++)
cin >> v[i];
sort(v + 1, v + n + 1);
if(n == 1)
{
cout << 1;
return 0;
}
memset(dp, -1, sizeof(dp));
v[0] = v[1];
cout << solve(0, 0, 0, 0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Incorrect |
155 ms |
245112 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
141 ms |
245112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Incorrect |
155 ms |
245112 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |