This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx,avx2")
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
void init(int N, vector<int> H) {
a = H;
}
int calc(int l, int r, int h, int d){
if (l > r) return 0;
if (r - l + 1 <= 2) return a[l] <= h || a[r] <= h;
int ans = 0;
int m = l;
for (int i = l; i <= r; i++){
if (a[i] > a[m]) m = i;
if (a[i] <= h) ans = 1;
}
ans = max(ans, calc(l, m - 1, a[m] - d, d) + calc(m + 1, r, a[m] - d, d));
return ans;
}
int max_towers(int L, int R, int D) {
return calc(L, R, 2e9, 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... |