답안 #954701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954701 2024-03-28T11:41:47 Z tleSquared 송신탑 (IOI22_towers) C++17
0 / 100
4000 ms 5136 KB
#include <bits/stdc++.h>
#define INF 1e18

using namespace std;

vector<int> H;
vector<int> seg;
int N;

void build(int v, int l, int r)
{
    // for (int i = 0; i < N; i++) seg[N+i] = H[i];

    // for (int i = N-1; i >= 1; i--) seg[i] = max(seg[2*i], seg[2*i+1]);

    if (l == r) seg[v] = H[l];
    else
    {
        int mid = (l + r) / 2;

        build(2 * v, l, mid);
        build(2 * v + 1, mid+1, r);

        seg[v] = max(seg[2*v], seg[2*v+1]);
    }
}

int max_query(int v, int l, int r, int q_l, int q_r)
{
    if (l > q_r || r < q_l) return 0;
    if (l >= q_l && r <= q_r) return seg[v];
    int mid = (l + r) / 2;
    return max(max_query(2 * v, l, mid, q_l, q_r), max_query(2 * v + 1, mid+1, r, q_l, q_r));
}

bool check(pair<int, int> f, pair<int, int> s, int d)
{
    return (s.first <= (max_query(0, 0, N-1, min(f.second, s.second)+1, max(f.second, s.second)-1)-d));
}

void init(int n, vector<int> h)
{
    H = h;
    N = n;
    seg.resize(4*N);
    build(0, 0, N-1);
}

int max_towers(int L, int R, int D)
{
    vector<pair<int, int>> r;
    for (int i = L; i <= R; i++) r.push_back({H[i], i});
    sort(r.begin(), r.end());

    pair<int, int> last = r[0];
    int ans = 1;
    for (int i = 1; i < r.size(); i++)
    {
        if (min(last.second, r[i].second)+1 < max(last.second, r[i].second))
        {
            if (check(last, r[i], D))
            {
                ans++;
                last = r[i];
            }
            else break;
        }
    }

    return ans;
}

// int main()
// {
//     init(7, {10, 20, 60, 40, 50, 30, 70});

//     cout << max_towers(1, 5, 10) << endl; // Ans:- 3

//     cout << max_towers(2, 2, 100) << endl; // Ans:- 1

//     cout << max_towers(0, 6, 17) << endl; // Ans:- 2

//     return 0;
// }

Compilation message

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for (int i = 1; i < r.size(); i++)
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4078 ms 3612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 500 KB 1st lines differ - on the 1st token, expected: '13', found: '29'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 500 KB 1st lines differ - on the 1st token, expected: '13', found: '29'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4025 ms 5136 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4011 ms 2168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 500 KB 1st lines differ - on the 1st token, expected: '13', found: '29'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4078 ms 3612 KB Time limit exceeded
2 Halted 0 ms 0 KB -