이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#ifndef EVAL
#include <format>
#include <iostream>
template <typename... Args>
void print(std::format_string<Args...> fmt, Args &&...args) {
std::cerr << std::format(fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void println(std::format_string<Args...> fmt, Args &&...args) {
std::cerr << std::format(fmt, std::forward<Args>(args)...) << '\n';
}
#else
template <typename... T> void print(T &&...args) {}
template <typename... T> void println(T &&...args) {}
#endif
int n;
std::vector<int> h;
std::vector<int> minima_sums;
void init(int N, std::vector<int> H) {
n = N;
h = H;
minima_sums.reserve(N + 1);
minima_sums.push_back(0);
for (int i = 0; i < N; i++) {
bool left_ok = i == 0 || H[i - 1] > H[i];
bool right_ok = i + 1 == N || H[i + 1] > H[i];
minima_sums.push_back(minima_sums.back() + (left_ok && right_ok));
}
}
int max_towers(int L, int R, int D) {
if (L == R)
return 1;
R += 1;
if (D == 1) {
int total = minima_sums[R - 1] - minima_sums[L + 1];
if (h[L + 1] > h[L]) {
total += 1;
}
if (h[R - 2] > h[R - 1]) {
total += 1;
}
return total;
} else {
std::vector<int> included{h[L]};
int greatest = h[L];
for (int i = L + 1; i < R; i++) {
if (h[i] > greatest) {
// println("Found new intermediary: {}", h[i]);
greatest = h[i];
} else if (greatest - included.back() < D) {
if (h[i] < included.back()) {
// println("Found better tower: {} instead of {}", h[i],
// included.back());
included.pop_back();
included.push_back(h[i]);
greatest = h[i];
} else {
// println("Found new tower, but it's worse: {} instead of {}", h[i],
// included.back());
}
} else if (greatest - h[i] >= D) {
// println("Found new tower: {} (previous was {}, greatest: {})", h[i],
// included.back(), greatest);
included.push_back(h[i]);
greatest = h[i];
}
}
return included.size();
}
}
# | 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... |