#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 20;
bool sub1;
int cnt_min[maxN];
int H[maxN];
int N;
int max_id;
void init(int _N, vector<int> _H) {
N = _N;
for (int i = 0; i < N; i++) {
H[i] = _H[i];
}
max_id = 0;
for (int i = 0; i < N; i++) {
if (H[i] > H[max_id]) {
max_id = i;
}
}
sub1 = true;
for (int i = 0; i < max_id; i++) {
sub1 &= H[i] < H[i + 1];
}
for (int i = max_id; i + 1 < N; i++) {
sub1 &= H[i] > H[i + 1];
}
for (int i = 1; i < N - 1; i++) {
cnt_min[i] = cnt_min[i - 1] + (H[i] < H[i - 1] && H[i] < H[i + 1]);
}
}
int max_towers(int L, int R, int D) {
if (L == R) {
return 1;
}
if (sub1) {
if (R <= max_id) {
return 1;
}
else if (L >= max_id) {
return 1;
}
else {
return 1 + (H[max_id] >= max(H[L], H[R]) + D);
}
}
if (D == 1) {
return cnt_min[R - 1] - cnt_min[L] + (H[L] < H[L + 1]) + (H[R] < H[R - 1]);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
1232 KB |
Output is correct |
2 |
Correct |
471 ms |
1744 KB |
Output is correct |
3 |
Correct |
694 ms |
1840 KB |
Output is correct |
4 |
Correct |
641 ms |
1872 KB |
Output is correct |
5 |
Correct |
585 ms |
1872 KB |
Output is correct |
6 |
Correct |
590 ms |
1828 KB |
Output is correct |
7 |
Correct |
627 ms |
1852 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
464 ms |
1856 KB |
Output is correct |
2 |
Correct |
643 ms |
1996 KB |
Output is correct |
3 |
Correct |
694 ms |
1872 KB |
Output is correct |
4 |
Correct |
573 ms |
1872 KB |
Output is correct |
5 |
Correct |
698 ms |
1872 KB |
Output is correct |
6 |
Correct |
575 ms |
1848 KB |
Output is correct |
7 |
Correct |
741 ms |
1744 KB |
Output is correct |
8 |
Correct |
688 ms |
1872 KB |
Output is correct |
9 |
Correct |
549 ms |
1856 KB |
Output is correct |
10 |
Correct |
766 ms |
1744 KB |
Output is correct |
11 |
Correct |
712 ms |
1744 KB |
Output is correct |
12 |
Correct |
750 ms |
1872 KB |
Output is correct |
13 |
Correct |
565 ms |
1836 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
10 ms |
1860 KB |
Output is correct |
18 |
Correct |
10 ms |
1832 KB |
Output is correct |
19 |
Correct |
10 ms |
1840 KB |
Output is correct |
20 |
Correct |
10 ms |
1840 KB |
Output is correct |
21 |
Correct |
10 ms |
1840 KB |
Output is correct |
22 |
Correct |
19 ms |
1844 KB |
Output is correct |
23 |
Correct |
17 ms |
1736 KB |
Output is correct |
24 |
Correct |
10 ms |
1868 KB |
Output is correct |
25 |
Correct |
10 ms |
1836 KB |
Output is correct |
26 |
Correct |
10 ms |
1872 KB |
Output is correct |
27 |
Correct |
0 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
208 KB |
Output is correct |
35 |
Correct |
0 ms |
336 KB |
Output is correct |
36 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
180 ms |
592 KB |
1st lines differ - on the 1st token, expected: '7197', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
1232 KB |
Output is correct |
2 |
Correct |
471 ms |
1744 KB |
Output is correct |
3 |
Correct |
694 ms |
1840 KB |
Output is correct |
4 |
Correct |
641 ms |
1872 KB |
Output is correct |
5 |
Correct |
585 ms |
1872 KB |
Output is correct |
6 |
Correct |
590 ms |
1828 KB |
Output is correct |
7 |
Correct |
627 ms |
1852 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '0' |
12 |
Halted |
0 ms |
0 KB |
- |