Submission #762371

# Submission time Handle Problem Language Result Execution time Memory
762371 2023-06-21T10:57:18 Z doowey Radio Towers (IOI22_towers) C++17
11 / 100
4000 ms 10648 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);
    }
}

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();
    //int sol1 = (int)lis.size() - id;
    int sol2 = solve(L, R, delta, (int)1e9 + 1);
    //cout << sol1 << " " << sol2 << "\n";
    return sol2;
}

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;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 4059 ms 6508 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 2 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 6 ms 464 KB Output is correct
24 Correct 5 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 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 6 ms 464 KB Output is correct
33 Correct 5 ms 464 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 6 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 2 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 6 ms 464 KB Output is correct
24 Correct 5 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 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 6 ms 464 KB Output is correct
33 Correct 5 ms 464 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 6 ms 504 KB Output is correct
36 Correct 10 ms 6032 KB Output is correct
37 Correct 16 ms 9352 KB Output is correct
38 Correct 15 ms 9396 KB Output is correct
39 Correct 15 ms 9420 KB Output is correct
40 Correct 23 ms 9404 KB Output is correct
41 Correct 19 ms 9376 KB Output is correct
42 Correct 19 ms 9420 KB Output is correct
43 Correct 3131 ms 10468 KB Output is correct
44 Correct 14 ms 9420 KB Output is correct
45 Correct 14 ms 9660 KB Output is correct
46 Correct 13 ms 9388 KB Output is correct
47 Correct 18 ms 9364 KB Output is correct
48 Correct 23 ms 9380 KB Output is correct
49 Correct 15 ms 9376 KB Output is correct
50 Correct 666 ms 9908 KB Output is correct
51 Correct 2134 ms 10648 KB Output is correct
52 Correct 22 ms 9412 KB Output is correct
53 Correct 27 ms 9380 KB Output is correct
54 Correct 25 ms 9388 KB Output is correct
55 Execution timed out 4027 ms 9676 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4034 ms 9408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4062 ms 2384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 2 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 6 ms 464 KB Output is correct
24 Correct 5 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 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 6 ms 464 KB Output is correct
33 Correct 5 ms 464 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 6 ms 504 KB Output is correct
36 Correct 10 ms 6032 KB Output is correct
37 Correct 16 ms 9352 KB Output is correct
38 Correct 15 ms 9396 KB Output is correct
39 Correct 15 ms 9420 KB Output is correct
40 Correct 23 ms 9404 KB Output is correct
41 Correct 19 ms 9376 KB Output is correct
42 Correct 19 ms 9420 KB Output is correct
43 Correct 3131 ms 10468 KB Output is correct
44 Correct 14 ms 9420 KB Output is correct
45 Correct 14 ms 9660 KB Output is correct
46 Correct 13 ms 9388 KB Output is correct
47 Correct 18 ms 9364 KB Output is correct
48 Correct 23 ms 9380 KB Output is correct
49 Correct 15 ms 9376 KB Output is correct
50 Correct 666 ms 9908 KB Output is correct
51 Correct 2134 ms 10648 KB Output is correct
52 Correct 22 ms 9412 KB Output is correct
53 Correct 27 ms 9380 KB Output is correct
54 Correct 25 ms 9388 KB Output is correct
55 Execution timed out 4027 ms 9676 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4059 ms 6508 KB Time limit exceeded
2 Halted 0 ms 0 KB -