답안 #835333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
835333 2023-08-23T13:15:44 Z SamAnd 송신탑 (IOI22_towers) C++17
0 / 100
4000 ms 3352 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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2883 ms 2148 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4086 ms 3352 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2425 ms 976 KB 2nd lines differ - on the 1st token, expected: '7063', found: '7197'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2883 ms 2148 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -