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 <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
const int MAXN = 100000 + 10;
const int INF = 1e9;
int n;
int h[MAXN];
int perm[MAXN];
void init(int N, std::vector <int> H)
{
n = N;
for (int i = 0 ; i < n ; ++i)
{
h[i + 1] = H[i];
}
}
bool used[MAXN];
int max_towers(int l, int r, int d)
{
l++; r++;
std::iota(perm + l, perm + r + 1, l);
std::sort(perm + l, perm + r + 1, [&](int x, int y)
{
return h[x] < h[y];
});
int ans = 0;
for (int i = l ; i <= r ; ++i)
{
int max = -1;
bool can = true;
int pos = perm[i];
for (int j = pos - 1 ; j >= l && can ; --j)
{
if (used[j])
{
if (max - d < std::max(h[j], h[pos]))
{
can = false;
} else
{
break;
}
}
max = std::max(max, h[j]);
}
max = -1;
for (int j = pos + 1 ; j <= r && can ; ++j)
{
if (used[j])
{
if (max - d < std::max(h[j], h[pos]))
{
can = false;
} else
{
break;
}
}
max = std::max(max, h[j]);
}
if (can)
{
ans++;
used[pos] = true;
}
}
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... |