Submission #835334

# Submission time Handle Problem Language Result Execution time Memory
835334 2023-08-23T13:19:06 Z SamAnd Radio Towers (IOI22_towers) C++17
0 / 100
4000 ms 3400 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 100005;

int n, d;
int a[N];

int ul[N], ur[N];
vector<pair<int, int> > b;

bool sos(const pair<int, int>& a, const pair<int, int>& b)
{
    return a.se < b.se;
}

void pre()
{
    b.clear();

    vector<int> s;
    for (int i = 1; i <= n; ++i)
    {
        while (!s.empty() && a[s.back()] <= a[i])
            s.pop_back();
        s.push_back(i);

        int l = 0, r = sz(s) - 1;
        ul[i] = 0;
        while (l <= r)
        {
            int m = (l + r) / 2;
            if (a[s[m]] - d >= a[i])
            {
                ul[i] = s[m];
                l = m + 1;
            }
            else
            {
                r = m - 1;
            }
        }
    }
    s.clear();
    for (int i = n; i >= 1; --i)
    {
        while (!s.empty() && a[s.back()] <= a[i])
            s.pop_back();
        s.push_back(i);

        int l = 0, r = sz(s) - 1;
        ur[i] = n + 1;
        while (l <= r)
        {
            int m = (l + r) / 2;
            if (a[s[m]] - d >= a[i])
            {
                ur[i] = s[m];
                l = m + 1;
            }
            else
                r = m - 1;
        }
    }

    for (int i = 1; i <= n; ++i)
    {
        b.push_back(m_p(ul[i] + 1, ur[i] - 1));
    }
    sort(all(b), sos);
}

void init(int N, std::vector<int> H)
{
    n = N;
    for (int i = 1; i <= n; ++i)
        a[i] = H[i - 1];
}

int max_towers(int L, int R, int D)
{
    ++L;
    ++R;
    //if (b.empty())
    {
        d = D;
        pre();
    }

    int ans = 0;
    int u = 0;
    for (int i = 0; i < sz(b); ++i)
    {
        if (max(L, b[i].fi) <= min(R, b[i].se))
        {
            if (b[i].fi > u)
            {
                u = b[i].se;
                ++ans;
            }
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4022 ms 2244 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '91', found: '92'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '91', found: '92'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4091 ms 3400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4054 ms 976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '91', found: '92'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4022 ms 2244 KB Time limit exceeded
2 Halted 0 ms 0 KB -