This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Author: Kajetan Ramsza
#include "bits/stdc++.h"
#include "towers.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#ifdef DEBUG
auto &operator<<(auto &os, const pair<auto, auto> &p) {
return os<<"("<<p.first<<", "<<p.second<<")";
}
auto &operator<<(auto &os, const auto &v) {
os << "{";
for(auto it=begin(v);it!=end(v);it++) {
if(it != begin(v)) os<<", ";
os<<(*it);
}
return os<<"}";
}
void dbg_out(auto... x) {
((cerr<<' '<<x), ...) << endl;
}
#define dbg(x...) cerr<<"("<<#x<<"):", dbg_out(x)
#else
#define dbg(...)
#endif
const int inf = 2e9 + 7;
int n;
vi h;
void init(int N, vi H) {
n = N;
h = H;
}
int max_towers(int L, int R, int D) {
int num = 0;
int prev = inf;
bool small = false;
rep(i,L,R+1) {
if(small) {
if(h[i] < prev) {
prev = h[i];
}
else if(h[i] - D >= prev) {
num++;
prev = h[i];
small = false;
}
} else {
if(h[i] > prev) {
prev = h[i];
}
else if(h[i] + D <= prev) {
num++;
prev = h[i];
small = true;
}
}
}
// if(num == 0) return 1;
return (num + 1) / 2;
}
# | 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... |