#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "BAI1"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
inline int readInt() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ll readLong() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}
const int N = 1e2 + 3;
const int M = 1e3 + 3;
const int LOG = 50;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
int n, L;
int dp[2][N][M][4];
int a[N];
void add(int &x, int y)
{
x += y;
if(x >= MOD) x -= MOD;
}
int mul(int x, int y) {return 1ll * x * y % MOD;}
void solve()
{
cin >> n >> L;
rep(i, n) cin >> a[i];
sort(a + 1, a + 1 + n);
int f = 0;
dp[0][1][0][0] = 1;
dp[0][1][0][1] = 2;
forn(i, 2, n)
{
for(int num_cc = 1; num_cc <= n; ++num_cc)
for(int sum = 0; sum <= L; ++sum)
for(int num_ends = 0; num_ends <= 2; ++num_ends) dp[f ^ 1][num_cc][sum][num_ends] = 0;
for(int num_cc = 1; num_cc <= n; ++num_cc)
for(int sum = 0; sum <= L; ++sum)
for(int num_ends = 0; num_ends <= 2; ++num_ends)
if(dp[f][num_cc][sum][num_ends]) {
int new_sum = sum + (a[i] - a[i - 1]) * (2 * num_cc - num_ends);
if(new_sum <= L)
{
#define trans(x, y, z) add(dp[f ^ 1][num_cc + x][new_sum][num_ends + y], mul(dp[f][num_cc][sum][num_ends], z));
trans(-1, 0, num_cc - 1); /// merge cc
trans(1, 0, num_cc + 1 - num_ends); /// create cc
trans(0, 0, 2 * num_cc - num_ends); /// append cc
trans(1, 1, 2 - num_ends); /// create end
trans(0, 1, 2 - num_ends); /// append end
}
}
f ^= 1;
}
int res = 0;
for(int sum = 0; sum <= L; ++sum) add(res, dp[f][1][sum][2]);
cout << res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int TC = 1;
if(fopen("note.inp", "r"))
{
freopen("note.inp", "r", stdin);
freopen("note.out", "w", stdout);
}
while(TC--)
{
solve();
cout << endl;
}
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | freopen("note.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | freopen("note.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |