//khodaya khodet komak kon
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 100 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;
int dp[N][1010][N][3], n, a[N], L;
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> L;
//assert(n == 1);
for (int i = 1; i <= n; i++) cin >> a[i];
if (n == 1){
return cout << 1, 0;
}
sort(a + 1, a + n + 1);
dp[1][0][0][1] = 2;
dp[1][0][0][2] = 1;
for (int i = 1; i < n; i++) for (int sm = 0; sm <= L; sm++) for (int cnt = 0; cnt <= i + 1; cnt++) for (int cor = 0; cor <= 2; cor++){
if (cnt + cor == 0) continue;
int delta = a[i + 1] - a[i];
int num = min(1009* 1ll, sm + (cnt * 2 + cor) * delta);
//if (dp[i][sm][cnt][cor] != 0) cout << num << '\n';
if (cnt != 0){
dp[i + 1][num][cnt - 1][cor] += (cnt * dp[i][sm][cnt][cor]) % MOD;
dp[i + 1][num][cnt - 1][cor] %= MOD;
dp[i + 1][num][cnt + 1][cor] += (cnt * dp[i][sm][cnt][cor]) % MOD;
dp[i + 1][num][cnt + 1][cor] %= MOD;
dp[i + 1][num][cnt][cor] += (cnt * 2 * dp[i][sm][cnt][cor]) % MOD;
dp[i + 1][num][cnt][cor] %= MOD;
}
if (cor != 0){
//cout << "YES" << endl;
dp[i + 1][num][cnt + 1][cor - 1] += cor * dp[i][sm][cnt][cor];
dp[i + 1][num][cnt + 1][cor - 1] %= MOD;
dp[i + 1][num][cnt + 1][cor] += cor * dp[i][sm][cnt][cor];
dp[i + 1][num][cnt + 1][cor] %= MOD;
dp[i + 1][num][cnt][cor - 1] += cor * dp[i][sm][cnt][cor];
dp[i + 1][num][cnt][cor - 1] %= MOD;
dp[i + 1][num][cnt][cor] += cor * dp[i][sm][cnt][cor];
dp[i + 1][num][cnt][cor] %= MOD;
}
}
ll ans = 0;
for (int i = 0; i <= L; i++) ans += dp[n][i][0][0], ans %= MOD;
cout << ans;
return 0;
}
Compilation message
skyscraper.cpp:8:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
#pragma GCC optimise ("ofast")
skyscraper.cpp:9:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
#pragma GCC optimise("unroll-loops")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
7 ms |
3192 KB |
Output is correct |
5 |
Correct |
20 ms |
16248 KB |
Output is correct |
6 |
Correct |
19 ms |
16248 KB |
Output is correct |
7 |
Correct |
11 ms |
8568 KB |
Output is correct |
8 |
Correct |
6 ms |
2424 KB |
Output is correct |
9 |
Correct |
19 ms |
16764 KB |
Output is correct |
10 |
Correct |
8 ms |
3832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2680 KB |
Output is correct |
2 |
Correct |
11 ms |
8056 KB |
Output is correct |
3 |
Correct |
7 ms |
2680 KB |
Output is correct |
4 |
Correct |
11 ms |
8444 KB |
Output is correct |
5 |
Correct |
11 ms |
8440 KB |
Output is correct |
6 |
Correct |
9 ms |
5624 KB |
Output is correct |
7 |
Correct |
7 ms |
2680 KB |
Output is correct |
8 |
Correct |
6 ms |
2552 KB |
Output is correct |
9 |
Correct |
8 ms |
3708 KB |
Output is correct |
10 |
Correct |
10 ms |
7544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
7 ms |
3192 KB |
Output is correct |
5 |
Correct |
20 ms |
16248 KB |
Output is correct |
6 |
Correct |
19 ms |
16248 KB |
Output is correct |
7 |
Correct |
11 ms |
8568 KB |
Output is correct |
8 |
Correct |
6 ms |
2424 KB |
Output is correct |
9 |
Correct |
19 ms |
16764 KB |
Output is correct |
10 |
Correct |
8 ms |
3832 KB |
Output is correct |
11 |
Correct |
6 ms |
2680 KB |
Output is correct |
12 |
Correct |
11 ms |
8056 KB |
Output is correct |
13 |
Correct |
7 ms |
2680 KB |
Output is correct |
14 |
Correct |
11 ms |
8444 KB |
Output is correct |
15 |
Correct |
11 ms |
8440 KB |
Output is correct |
16 |
Correct |
9 ms |
5624 KB |
Output is correct |
17 |
Correct |
7 ms |
2680 KB |
Output is correct |
18 |
Correct |
6 ms |
2552 KB |
Output is correct |
19 |
Correct |
8 ms |
3708 KB |
Output is correct |
20 |
Correct |
10 ms |
7544 KB |
Output is correct |
21 |
Correct |
13 ms |
8952 KB |
Output is correct |
22 |
Correct |
302 ms |
183136 KB |
Output is correct |
23 |
Correct |
517 ms |
256248 KB |
Output is correct |
24 |
Correct |
417 ms |
241656 KB |
Output is correct |
25 |
Correct |
522 ms |
256412 KB |
Output is correct |
26 |
Correct |
463 ms |
251852 KB |
Output is correct |
27 |
Correct |
153 ms |
89976 KB |
Output is correct |
28 |
Correct |
176 ms |
104184 KB |
Output is correct |
29 |
Correct |
324 ms |
193016 KB |
Output is correct |
30 |
Correct |
515 ms |
256408 KB |
Output is correct |