답안 #762377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762377 2023-06-21T11:06:41 Z doowey 송신탑 (IOI22_towers) C++17
17 / 100
787 ms 9920 KB
#include <bits/stdc++.h>
#include "towers.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair

const int N = (int)1e5 + 10;
const int LOG = 17;
int L[N], R[N];
int tab[LOG][N];
int G[N];
int n;
int H[N];

int get_max(int l, int r){
    int sz = (r - l + 1);
    return max(tab[G[sz]][l], tab[G[sz]][r - (1 << G[sz]) + 1]);
}

vector<int> lis;

void init(int _n, vector<int> _H) {
    n = _n;
    for(int i = 0 ; i < n; i ++ ){
        L[i] = R[i] = -1;
        H[i] = _H[i];
    }
    vector<int> ord;
    for(int i = 0 ; i < n; i ++ ){
        tab[0][i] = H[i];
        // ------------------
        while(!ord.empty() && H[ord.back()] > H[i]){
            R[ord.back()] = i;
            ord.pop_back();
        }
        if(!ord.empty()){
            L[i] = ord.back();
        }
        ord.push_back(i);
    }
    for(int ln = 1; ln < LOG; ln ++ ){
        for(int i = 0 ; i < n; i ++){
            if((i + (1 << ln) - 1) < n){
                tab[ln][i] = max(tab[ln - 1][i], tab[ln - 1][i + (1 << (ln - 1))]);
            }
        }
    }
    int lg = 0;
    for(int sz = 1; sz <= n; sz ++ ){
        while((1 << (lg + 1)) <= sz){
            lg ++ ;
        }
        G[sz] = lg;
    }
    int maxi;
    int need;
    for(int i = 0; i < n; i ++ ){
        need = (int)1e9;
        if(L[i] != -1){
            need = min(need, get_max(L[i],i)-H[i]);
        }
        if(R[i] != -1){
            need = min(need, get_max(i,R[i])-H[i]);
        }
        lis.push_back(need);
    }
    sort(lis.begin(), lis.end());
}

int solve(int l, int r, int delta, int bound){
    if(l>r) return 0;
    int big = l;
    bool emp = true;
    for(int i = l ; i <= r; i ++ ){
        if(H[i] > H[big]) big = i;
        if(H[i] <= bound){
            emp = false;
        }
    }
    if(emp) return 0;
    return max(1, solve(l,big-1,delta,H[big]-delta)+solve(big+1,r,delta,H[big]-delta));
}


int max_towers(int L, int R, int delta) {
    int id = lower_bound(lis.begin(), lis.end(), delta) - lis.begin();
    return (int)lis.size() - id;
}

Compilation message

towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:61:9: warning: unused variable 'maxi' [-Wunused-variable]
   61 |     int maxi;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 375 ms 5836 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 555 ms 9392 KB 1st lines differ - on the 1st token, expected: '11903', found: '33010'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 2384 KB Output is correct
2 Correct 675 ms 9380 KB Output is correct
3 Correct 787 ms 9420 KB Output is correct
4 Correct 763 ms 9420 KB Output is correct
5 Correct 787 ms 9500 KB Output is correct
6 Correct 630 ms 9404 KB Output is correct
7 Correct 611 ms 9380 KB Output is correct
8 Correct 683 ms 9872 KB Output is correct
9 Correct 575 ms 9396 KB Output is correct
10 Correct 663 ms 9792 KB Output is correct
11 Correct 591 ms 9420 KB Output is correct
12 Correct 18 ms 9384 KB Output is correct
13 Correct 18 ms 9436 KB Output is correct
14 Correct 23 ms 9396 KB Output is correct
15 Correct 15 ms 9360 KB Output is correct
16 Correct 15 ms 9556 KB Output is correct
17 Correct 20 ms 9124 KB Output is correct
18 Correct 18 ms 9376 KB Output is correct
19 Correct 19 ms 9376 KB Output is correct
20 Correct 18 ms 9380 KB Output is correct
21 Correct 18 ms 9444 KB Output is correct
22 Correct 18 ms 9420 KB Output is correct
23 Correct 19 ms 9384 KB Output is correct
24 Correct 15 ms 9920 KB Output is correct
25 Correct 22 ms 9376 KB Output is correct
26 Correct 21 ms 9640 KB Output is correct
27 Correct 16 ms 9400 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 0 ms 336 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 1 ms 464 KB Output is correct
39 Correct 1 ms 464 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 1 ms 464 KB Output is correct
42 Correct 1 ms 464 KB Output is correct
43 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 375 ms 5836 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -