#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;
#define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"
template<class X, class Y>
bool minz(X &x, const Y &y) {
if (x > y) {
x = y;
return true;
} return false;
}
template<class X, class Y>
bool maxz(X &x, const Y &y) {
if (x < y) {
x = y;
return true;
} return false;
}
const int N = 5e5 + 5;
const ll oo = (ll) 1e16;
const ll mod = 1e9 + 7; // 998244353;
ll n, l, a[N], dp[101][101][1002][3];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef hqm
freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
#endif
cin >> n >> l;
forr (i, 1, n){
cin >> a[i];
}
sort(a + 1, a + 1 + n);
dp[1][0][0][0] = 1;
ll res = 0;
forr (i, 1, n){
forr (j, 0, n){
forr (k, 0, l){
forr (t, 0, 2){
//if (j == 0 && t != 0) continue;
if (dp[i][j][k][t]){
// cout << i << " " << j << " " << k << " " << t << " " << dp[i][j][k][t] << "\n";
}
int nk;
nk = min(l + 1, k + ((j + 1) * 2 - t) * (a[i + 1] - a[i]));
(dp[i + 1][j + 1][nk][t] += dp[i][j][k][t] * (j + 1 - t)) %= mod;
nk = min(l + 1, k + ((j + 1) * 2 - (t + 1)) * (a[i + 1] - a[i]));
(dp[i + 1][j + 1][nk][t + 1] += dp[i][j][k][t] * (2 - t)) %= mod;
if (j >= 1){
nk = min(l + 1, k + (j * 2 - t) * (a[i + 1] - a[i]));
(dp[i + 1][j][nk][t] += dp[i][j][k][t] * (2 * j - t)) %= mod;
nk = min(l + 1, k + (j * 2 - (t + 1)) * (a[i + 1] - a[i]));
(dp[i + 1][j][nk][t + 1] += dp[i][j][k][t] * (2 - t)) %= mod;
}
if (j - t >= 2){
nk = min (l + 1, k + ((j - 1) * 2 - t) * (a[i + 1] - a[i]));
(dp[i + 1][j - 1][nk][t] += dp[i][j][k][t] * (j - t - 1)) %= mod;
}
if (t && j > t){
nk = min(l + 1, k + ((j - 1) * 2 - t) * (a[i + 1] - a[i]));
(dp[i + 1][j - 1][nk][t] += dp[i][j][k][t] * t) %= mod;
}
if (t == 2 && j == 2 && i == n){
res += dp[i][j][k][t];
}
if (t == 1 && j == 1 && i == n){
res += dp[i][j][k][t];
}
}
}
}
}
cout << res % mod;
return 0;
}
/*
*/
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:72:50: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
72 | (dp[i + 1][j + 1][nk][t + 1] += dp[i][j][k][t] * (2 - t)) %= mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:9:46: note: within this loop
9 | #define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
| ^
skyscraper.cpp:63:17: note: in expansion of macro 'forr'
63 | forr (t, 0, 2){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5464 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
3 ms |
5592 KB |
Output is correct |
4 |
Correct |
2 ms |
5724 KB |
Output is correct |
5 |
Correct |
3 ms |
5792 KB |
Output is correct |
6 |
Correct |
3 ms |
5724 KB |
Output is correct |
7 |
Correct |
3 ms |
5468 KB |
Output is correct |
8 |
Correct |
2 ms |
5468 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
2 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |