#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <random>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
#define MP make_pair
typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.000001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 2e6 + 3e2;
const int M = 1111;
long long skyscraper_combinations(int n, int l, vector<int> a){
vector<vector<vector<ll>>> dp(1 << n, vector<vector<ll>>(n, vector<ll>(l + 1, 0)));
for (int i = 0; i < n; i++) dp[1 << i][i][0] = 1;
for (int mask = 0; mask < (1 << n); mask++){
for (int i = 0; i < n; i++){
if (!(mask & (1 << i))) continue;
for (int j = 0; j < n; j++){
if (mask & (1 << j)) continue;
int diff = abs(a[i] - a[j]);
for (int k = 0; k + diff <= l; k++){
(dp[mask | (1 << j)][j][k + diff] += dp[mask][i][k]) %= MOD;
}
}
}
}
ll ans = 0;
for (int i = 0; i < n; i++){
ans += accumulate(all(dp[(1 << n) - 1][i]), 0ll);
ans %= MOD;
}
return ans;
}
void solve(int TC) {
int n, l;
cin >> n >> l;
vector<int> a(n);
for (int &i : a) cin >> i;
cout << skyscraper_combinations(n, l, a) << endl;
}
int main() {
startTime = clock();
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef dddxxz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int TC = 1;
// cin >> TC;
for (int test = 1; test <= TC; test++) {
//debug(test);
//cout << "Case #" << test << ": ";
solve(test);
}
#ifdef dddxxz
cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
#endif
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
10 ms |
15572 KB |
Output is correct |
6 |
Correct |
9 ms |
13968 KB |
Output is correct |
7 |
Correct |
2 ms |
2900 KB |
Output is correct |
8 |
Correct |
1 ms |
1620 KB |
Output is correct |
9 |
Correct |
11 ms |
14964 KB |
Output is correct |
10 |
Correct |
2 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
26964 KB |
Output is correct |
2 |
Correct |
210 ms |
182288 KB |
Output is correct |
3 |
Correct |
127 ms |
92536 KB |
Output is correct |
4 |
Correct |
212 ms |
185836 KB |
Output is correct |
5 |
Correct |
202 ms |
185932 KB |
Output is correct |
6 |
Correct |
221 ms |
175132 KB |
Output is correct |
7 |
Correct |
91 ms |
63704 KB |
Output is correct |
8 |
Correct |
123 ms |
88848 KB |
Output is correct |
9 |
Correct |
193 ms |
139224 KB |
Output is correct |
10 |
Correct |
189 ms |
160680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
10 ms |
15572 KB |
Output is correct |
6 |
Correct |
9 ms |
13968 KB |
Output is correct |
7 |
Correct |
2 ms |
2900 KB |
Output is correct |
8 |
Correct |
1 ms |
1620 KB |
Output is correct |
9 |
Correct |
11 ms |
14964 KB |
Output is correct |
10 |
Correct |
2 ms |
2260 KB |
Output is correct |
11 |
Correct |
36 ms |
26964 KB |
Output is correct |
12 |
Correct |
210 ms |
182288 KB |
Output is correct |
13 |
Correct |
127 ms |
92536 KB |
Output is correct |
14 |
Correct |
212 ms |
185836 KB |
Output is correct |
15 |
Correct |
202 ms |
185932 KB |
Output is correct |
16 |
Correct |
221 ms |
175132 KB |
Output is correct |
17 |
Correct |
91 ms |
63704 KB |
Output is correct |
18 |
Correct |
123 ms |
88848 KB |
Output is correct |
19 |
Correct |
193 ms |
139224 KB |
Output is correct |
20 |
Correct |
189 ms |
160680 KB |
Output is correct |
21 |
Runtime error |
5 ms |
7804 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |