#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e3 + 9;
const ll mod = 1e9 + 7;
typedef pair<ll,ll> LL;
ll n,l,dp[101][101][1001][3],a[N];
void Add(ll &a,ll b){
a = (a + b)%mod;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "tst"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n>>l;
for (ll i = 0;i < n;i++) cin>>a[i];
sort(a,a + n); a[n] = 1000000;
if (n == 1) return cout<<1,0;
if (a[1] - a[0] <= l) dp[1][1][a[1] - a[0]][1] = 2;
if (2*(a[1] - a[0]) <= l) dp[1][1][2*(a[1] - a[0])][0] = 1;
//cout<<dp[1][1][2*(a[1] - a[0])][0]; return 0;
for (ll i = 1;i < n;i++){
ll diff = a[i + 1] - a[i];
for (ll j = 1;j <= i;j++){
for (ll k = 0;k <= l;k++){
for (ll z = 0;z < 3;z++){
ll now = dp[i][j][k][z];
if (!now) continue;
//cout<<i<<" "<<j<<" "<<k<<" "<<z<<" ";
if (z < 2&&k + diff*(2*j - z - 1) <= l){
ll cur = k + diff*(2*j - z - 1);
if (i == n - 1) Add(dp[i + 1][j][cur][z + 1],now*(2 - z)*j);
else if (z == 0||j > 1) Add(dp[i + 1][j][cur][z + 1],now*(2 - z)*(j - z));
if (cur + 2*diff <= l) Add(dp[i + 1][j + 1][cur + 2*diff][z + 1],now*(2 - z));
}
if (k + diff*(2*j - z + 2) <= l)
Add(dp[i + 1][j + 1][k + diff*(2*j - z + 2)][z],now);
if (k + diff*(2*j - z) <= l)
Add(dp[i + 1][j][k + diff*(2*j - z)][z],now*(2*j - z));
if ((k + diff*(2*j - z - 2) <= l) && (j >= 2) && (i == n - 1 || j > 2 || z < 2)){
ll cur = k + diff*(2*j - z - 2);
if (!z) Add(dp[i + 1][j - 1][cur][z],now*j*(j - 1));
if (z == 1) Add(dp[i + 1][j - 1][cur][z],now*(j - 1)*(j - 1));
if (z == 2){
if (i == n - 1) Add(dp[i + 1][j - 1][cur][z],now);
else Add(dp[i + 1][j - 1][cur][z],now*(j - 2)*(j - 1));
}
}
}
}
}
}
//return 0;
ll ans = 0;
for (ll i = 0;i <= l;i++) Add(ans,dp[n][1][i][2]);
cout<<ans;
}
Compilation message
skyscraper.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization "O2"
|
skyscraper.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
1100 KB |
Output is correct |
22 |
Correct |
56 ms |
23872 KB |
Output is correct |
23 |
Correct |
51 ms |
7900 KB |
Output is correct |
24 |
Correct |
50 ms |
12120 KB |
Output is correct |
25 |
Correct |
52 ms |
9180 KB |
Output is correct |
26 |
Correct |
46 ms |
8408 KB |
Output is correct |
27 |
Correct |
23 ms |
9692 KB |
Output is correct |
28 |
Correct |
30 ms |
11980 KB |
Output is correct |
29 |
Correct |
48 ms |
16356 KB |
Output is correct |
30 |
Correct |
53 ms |
9256 KB |
Output is correct |