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 inf = 2e9 + 10;
int N;
vector<int> H;
vector<int> l, r;
void init(int _N, vector<int> _H) {
N = _N;
H = _H;
l.resize(N); r.resize(N);
for (int i=0; i<N; i++) {
l[i] = -1; r[i] = N;
for (int j=i-1; j>=0; j--) {
if (H[j] > H[i]) {
l[i] = j;
break;
}
}
for (int j=i+1; j<N; j++) {
if (H[j] > H[i]) {
r[i] = j;
break;
}
}
}
}
int max_towers(int L, int R, int D) {
int ans = 1;
for (int i=L; i<=R; i++) {
bool fl = false, fr = false;
for (int j=max(L-1, l[i])+1; j<=i-1; j++) {
if (H[j] <= H[i] - D) {
fl = true;
break;
}
}
for (int j=i+1; j<=min(R+1, r[i])-1; j++) {
if (H[j] <= H[i] - D) {
fr = true;
break;
}
}
if (fl && fr) ans ++;
}
return ans;
}
# | 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... |