#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> h;
int n;
void init(int N, vector<int> H) {
n = N;
h = H;
}
int max_towers(int l, int r, int D) {
vector<int> dp(n);
deque<pair<int, int>> st;
vector<int> nxt(n, -1);
for (int i = n - 1; i >= 0; i--) {
while (!st.empty() && h[st.front().second] <= h[i]) st.pop_front();
st.push_front({h[i], i});
auto p = lower_bound(st.begin(), st.end(), pair{h[i] + D, -1});
if (p != st.end()) {
nxt[i] = p->second;
}
}
st.clear();
vector<int> prev(n, -1);
for (int i = 0; i < n; i++) {
while (!st.empty() && h[st.front().second] <= h[i]) st.pop_front();
st.push_front({h[i], i});
auto p = lower_bound(st.begin(), st.end(), pair{h[i] + D, -1});
if (p != st.end()) {
prev[i] = p->second;
}
}
for (int i = l; i <= r; i++) {
dp[i] = 1;
for (int j = l; j < i; j++) {
if (nxt[j] < i && prev[i] > j) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
}
return *max_element(dp.begin(), dp.end());
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4040 ms |
1868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '14' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '14' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4038 ms |
2736 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4022 ms |
1036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '14' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4040 ms |
1868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |