This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2002;
int h[N];
bool f[N];
int n;
void init(int N, std::vector<int> H) {
n = N;
for (int i = 0; i < n; i++)
h[i] = H[i];
}
int solve (int l, int r, int d) {
if (l > r)
return 0;
if (l == r)
return f[l];
int mx = -1, in = -1;
for (int i = l; i <= r; i++) {
if (h[i] > mx) {
mx = h[i];
in = i;
}
}
int fin = (int)f[in];
//if (f[in]) {
for (int i = l; i <= r; i++) {
if (h[i] > mx - d)
f[i] = false;
}
//}
return max (fin, solve (l, in - 1, d) + solve(in + 1, r, d));
}
int max_towers(int L, int R, int D) {
for (int i = 0; i < N; i++)
f[i] = true;
return max (1, solve (L, R, D));
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |