#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int N, maxH[MAX][20];
bool isMountain = true;
vector<int> H;
int get(int l, int r) {
int k = log2(r - l + 1);
return max(maxH[l][k], maxH[r - (1 << k) + 1][k]);
}
void init(int _N, vector<int> _H) {
N = _N, H = _H;
for (int i = 0; i < N; i++)
maxH[i][0] = H[i];
for (int t = 1; t <= 18; t++)
for (int i = 0; i + (1 << t) - 1 < N; i++)
maxH[i][t] = max(maxH[i][t - 1], maxH[i + (1 << (t - 1))][t - 1]);
int id = max_element(H.begin(), H.end()) - H.begin();
for (int i = id; i > 0 && isMountain; i--)
isMountain &= (H[i] > H[i - 1]);
for (int i = id; i < N - 1 && isMountain; i++)
isMountain &= (H[i] > H[i + 1]);
}
int max_towers(int L, int R, int D) {
if (isMountain)
return get(L, R) - D >= max(H[L], H[R]) ? 2 : 1;
vector<int> f(N, 1);
int rs = 0;
for (int i = 1; i < N; i++) {
for (int j = 0; j < i - 1; j++)
if (get(j + 1, i - 1) - D >= max(H[i], H[j]))
f[i] = max(f[i], f[j] + 1);
rs = max(rs, f[i]);
}
return rs;
}
//int main() {
// freopen("../_input", "r", stdin);
// int N, Q;
// assert(2 == scanf("%d %d", &N, &Q));
// std::vector<int> H(N);
// for (int i = 0; i < N; ++i) {
// assert(1 == scanf("%d", &H[i]));
// }
// init(N, H);
//
// for (int i = 0; i < Q; ++i) {
// int L, R, D;
// assert(3 == scanf("%d %d %d", &L, &R, &D));
// printf("%d\n", max_towers(L, R, D));
// }
// return 0;
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
392 ms |
5664 KB |
Output is correct |
2 |
Correct |
882 ms |
9272 KB |
Output is correct |
3 |
Correct |
768 ms |
9248 KB |
Output is correct |
4 |
Correct |
950 ms |
9296 KB |
Output is correct |
5 |
Correct |
771 ms |
9252 KB |
Output is correct |
6 |
Correct |
805 ms |
9288 KB |
Output is correct |
7 |
Correct |
800 ms |
9296 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
336 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
336 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4027 ms |
9124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4078 ms |
2384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
336 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
392 ms |
5664 KB |
Output is correct |
2 |
Correct |
882 ms |
9272 KB |
Output is correct |
3 |
Correct |
768 ms |
9248 KB |
Output is correct |
4 |
Correct |
950 ms |
9296 KB |
Output is correct |
5 |
Correct |
771 ms |
9252 KB |
Output is correct |
6 |
Correct |
805 ms |
9288 KB |
Output is correct |
7 |
Correct |
800 ms |
9296 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Incorrect |
2 ms |
336 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
12 |
Halted |
0 ms |
0 KB |
- |