#include "towers.h"
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
//#define int long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef uint64_t u64;
typedef int64_t i64;
int n;
vi h;
int getMax(int l, int r) {
int best = 0;
for (int i = l; i <= r; i++) {
best = max(best, h[i]);
}
return best;
}
void init(int N, std::vector<int> H) {
//all H[i] are different
//dp[i] = max of 1 and all dp[j] over j s.t. j < i && maxH(j, i) - D >= max(H[i], H[j])
//D = 1
//H = 1, 2, 6, 4, 5, 3, 7
//dp= 1, 1, 1, 2, 2, 3, 1
n = N;
h = H;
}
int max_towers(int L, int R, int D) {
vi dp(n);
int res = 0;
for (int i = L; i <= R; i++) {
dp[i] = 1;
for (int j = L; j < i; j++) {
if (getMax(j + 1, i - 1) - D >= max(h[i], h[j])) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
res = max(res, dp[i]);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4030 ms |
1132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
144 ms |
344 KB |
Output is correct |
3 |
Correct |
96 ms |
344 KB |
Output is correct |
4 |
Correct |
39 ms |
344 KB |
Output is correct |
5 |
Correct |
90 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
59 ms |
428 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
11 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
67 ms |
344 KB |
Output is correct |
14 |
Correct |
32 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
346 ms |
592 KB |
Output is correct |
17 |
Correct |
19 ms |
344 KB |
Output is correct |
18 |
Correct |
5 ms |
344 KB |
Output is correct |
19 |
Correct |
19 ms |
456 KB |
Output is correct |
20 |
Correct |
865 ms |
344 KB |
Output is correct |
21 |
Correct |
864 ms |
424 KB |
Output is correct |
22 |
Correct |
874 ms |
428 KB |
Output is correct |
23 |
Correct |
862 ms |
344 KB |
Output is correct |
24 |
Correct |
870 ms |
344 KB |
Output is correct |
25 |
Correct |
77 ms |
344 KB |
Output is correct |
26 |
Correct |
865 ms |
432 KB |
Output is correct |
27 |
Correct |
880 ms |
428 KB |
Output is correct |
28 |
Correct |
870 ms |
344 KB |
Output is correct |
29 |
Correct |
878 ms |
344 KB |
Output is correct |
30 |
Correct |
876 ms |
344 KB |
Output is correct |
31 |
Correct |
864 ms |
344 KB |
Output is correct |
32 |
Correct |
880 ms |
432 KB |
Output is correct |
33 |
Correct |
893 ms |
424 KB |
Output is correct |
34 |
Correct |
863 ms |
344 KB |
Output is correct |
35 |
Correct |
879 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
144 ms |
344 KB |
Output is correct |
3 |
Correct |
96 ms |
344 KB |
Output is correct |
4 |
Correct |
39 ms |
344 KB |
Output is correct |
5 |
Correct |
90 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
59 ms |
428 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
11 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
67 ms |
344 KB |
Output is correct |
14 |
Correct |
32 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
346 ms |
592 KB |
Output is correct |
17 |
Correct |
19 ms |
344 KB |
Output is correct |
18 |
Correct |
5 ms |
344 KB |
Output is correct |
19 |
Correct |
19 ms |
456 KB |
Output is correct |
20 |
Correct |
865 ms |
344 KB |
Output is correct |
21 |
Correct |
864 ms |
424 KB |
Output is correct |
22 |
Correct |
874 ms |
428 KB |
Output is correct |
23 |
Correct |
862 ms |
344 KB |
Output is correct |
24 |
Correct |
870 ms |
344 KB |
Output is correct |
25 |
Correct |
77 ms |
344 KB |
Output is correct |
26 |
Correct |
865 ms |
432 KB |
Output is correct |
27 |
Correct |
880 ms |
428 KB |
Output is correct |
28 |
Correct |
870 ms |
344 KB |
Output is correct |
29 |
Correct |
878 ms |
344 KB |
Output is correct |
30 |
Correct |
876 ms |
344 KB |
Output is correct |
31 |
Correct |
864 ms |
344 KB |
Output is correct |
32 |
Correct |
880 ms |
432 KB |
Output is correct |
33 |
Correct |
893 ms |
424 KB |
Output is correct |
34 |
Correct |
863 ms |
344 KB |
Output is correct |
35 |
Correct |
879 ms |
436 KB |
Output is correct |
36 |
Execution timed out |
4029 ms |
1112 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4058 ms |
1492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4043 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
144 ms |
344 KB |
Output is correct |
3 |
Correct |
96 ms |
344 KB |
Output is correct |
4 |
Correct |
39 ms |
344 KB |
Output is correct |
5 |
Correct |
90 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
59 ms |
428 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
11 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
67 ms |
344 KB |
Output is correct |
14 |
Correct |
32 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
346 ms |
592 KB |
Output is correct |
17 |
Correct |
19 ms |
344 KB |
Output is correct |
18 |
Correct |
5 ms |
344 KB |
Output is correct |
19 |
Correct |
19 ms |
456 KB |
Output is correct |
20 |
Correct |
865 ms |
344 KB |
Output is correct |
21 |
Correct |
864 ms |
424 KB |
Output is correct |
22 |
Correct |
874 ms |
428 KB |
Output is correct |
23 |
Correct |
862 ms |
344 KB |
Output is correct |
24 |
Correct |
870 ms |
344 KB |
Output is correct |
25 |
Correct |
77 ms |
344 KB |
Output is correct |
26 |
Correct |
865 ms |
432 KB |
Output is correct |
27 |
Correct |
880 ms |
428 KB |
Output is correct |
28 |
Correct |
870 ms |
344 KB |
Output is correct |
29 |
Correct |
878 ms |
344 KB |
Output is correct |
30 |
Correct |
876 ms |
344 KB |
Output is correct |
31 |
Correct |
864 ms |
344 KB |
Output is correct |
32 |
Correct |
880 ms |
432 KB |
Output is correct |
33 |
Correct |
893 ms |
424 KB |
Output is correct |
34 |
Correct |
863 ms |
344 KB |
Output is correct |
35 |
Correct |
879 ms |
436 KB |
Output is correct |
36 |
Execution timed out |
4029 ms |
1112 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4030 ms |
1132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |