Submission #628753

# Submission time Handle Problem Language Result Execution time Memory
628753 2022-08-13T16:29:54 Z kingmoshe Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 14808 KB
//#include "towers.h"

#include <vector>
#include <iostream>
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
std::vector<int> real_h(0);
vvi maxi(0);
int total_maxi = 0;
bool is_interesting = false;


void init_maxi(int N) {
    maxi.resize(N, vi(0));
    for (int i = 0; i < N; i++) {
        maxi[i].push_back(i);
    }
    int size = 2;
    while (size <= N) {
        for (int i = 0; i < N; i += size) {
            int value = maxi[i][maxi[i].size() - 1];
            int next_place = i + (size / 2);
            if (next_place < N) {
                int other_value = maxi[next_place][maxi[next_place].size() - 1];
                if (real_h[other_value] > real_h[value]) {
                    value = other_value;
                }
            }
            maxi[i].push_back(value);
        }
        size *= 2;
    }
}

void init_is_interesting(int N) {
    bool going_up = true;
    for (int i = 1; i < N; i++) {
        if (real_h[i] < real_h[i - 1]) {
            if (going_up) {
                going_up = false;
            }
            else {
                return;
            }
        }
        else {
            if (!going_up) {
                return;
            }
        }
    }
    is_interesting = true;
}
void init(int N, std::vector<int> H) {
    real_h.resize(N);
    for (int i = 0; i < N; i++) {
        real_h[i] = H[i];
        if (real_h[i] > total_maxi) {
            total_maxi = real_h[i];
        }
    }
    init_maxi(N);

}

int get_max_id2(int l, int r) {
    if (l == r) {
        return l;
    }
    int size = 1;
    for (int i = 1; i < maxi[l].size(); i++) {
        if (l + size + size - 1 > r) {
            int temp_maxi = maxi[l][i - 1];
            if (l + size - 1 == r) {
                return temp_maxi;
            }
            else {
                int other_res = get_max_id2(l + size, r);
                if (real_h[other_res] > real_h[temp_maxi]) {
                    return other_res;
                }
                return temp_maxi;
            }
        }
        size *= 2;
    }
    int temp_maxi = maxi[l][maxi[l].size() - 1];
    if (l + size - 1 == r) {
        return temp_maxi;
    }
    else {
        int other_res = get_max_id2(l + size, r);
        if (real_h[other_res] > real_h[temp_maxi]) {
            return other_res;
        }
        return temp_maxi;
    }
}

int get_max_id(int l, int r) {
    int max_result = real_h[l];
    int max_id =l;
    for (int i = l + 1; i <= r; i++) {
        if (real_h[i] > max_result) {
            max_result = real_h[i];
            max_id = i;
        }
    }
    return max_id;
}

int get_min_id(int l, int r) {
    int min_result= real_h[l];
    int min_id =l;
    for (int i = l + 1; i <= r; i++) {
        if (real_h[i] < min_result) {
            min_result = real_h[i];
            min_id = i;
        }
    }
    return min_id;
}

int max_towers_interesting(int l, int r, int d) {
    int max_id = get_max_id2(l, r);
    if (l == r) {
        return 1;
    }
    if (real_h[max_id] != total_maxi) {
        return 1;
    }
    if (max_id == l) {
        return 1;
    }
    if (max_id == r) {
        return 1;
    }
    return 2;
}
int max_towers2(int l, int r, int d, int max_possible_value) {
    if (l > r) {
        return 0;
    }
    if (l == r) {
        if (real_h[l] <= max_possible_value) {
            return 1;
        }
        return 0;
    }
    if (l + 1 == r) {
        if (real_h[l] <= max_possible_value || real_h[l + 1] <= max_possible_value) {
            return 1;
        }
        return 0;
    }
    int max_id = get_max_id2(l, r);
    int left_value = max_towers2(l, max_id - 1, d, real_h[max_id] - d);
    int right_value = max_towers2(max_id + 1, r, d, real_h[max_id] - d);
    if (left_value + right_value == 0) {
        int min_id = get_min_id(l, r);
        if (real_h[min_id] <= max_possible_value) {
            return 1;
        }
    }
    return left_value + right_value;
}
int max_towers(int L, int R, int D) {
    if (is_interesting) {
        return max_towers_interesting(L, R, D);
    }
    return max_towers2(L, R, D, total_maxi);
}

/*int main() {
    init(7, std::vector<int>{10, 20, 60, 40, 50, 30, 70});
    std::cout << max_towers(1, 5, 10) << std::endl;
    std::cout << max_towers(2, 2, 100) << std::endl;
    std::cout << max_towers(0, 6, 17) << std::endl;

}//*/

Compilation message

towers.cpp: In function 'int get_max_id2(int, int)':
towers.cpp:71:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (int i = 1; i < maxi[l].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 4057 ms 7900 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 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
# 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 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 14 ms 4768 KB Output is correct
37 Correct 22 ms 7200 KB Output is correct
38 Correct 21 ms 7208 KB Output is correct
39 Correct 21 ms 7248 KB Output is correct
40 Correct 21 ms 7196 KB Output is correct
41 Correct 22 ms 7200 KB Output is correct
42 Correct 19 ms 7204 KB Output is correct
43 Correct 153 ms 10900 KB Output is correct
44 Correct 64 ms 7968 KB Output is correct
45 Correct 31 ms 7240 KB Output is correct
46 Correct 20 ms 7204 KB Output is correct
47 Correct 29 ms 7196 KB Output is correct
48 Correct 22 ms 7216 KB Output is correct
49 Correct 37 ms 7220 KB Output is correct
50 Correct 23 ms 8512 KB Output is correct
51 Correct 28 ms 9932 KB Output is correct
52 Correct 24 ms 7240 KB Output is correct
53 Correct 21 ms 7240 KB Output is correct
54 Correct 22 ms 7216 KB Output is correct
55 Correct 41 ms 14612 KB Output is correct
56 Correct 37 ms 13968 KB Output is correct
57 Correct 24 ms 6976 KB Output is correct
58 Correct 29 ms 7228 KB Output is correct
59 Correct 22 ms 7196 KB Output is correct
60 Correct 20 ms 7248 KB Output is correct
61 Correct 22 ms 7220 KB Output is correct
62 Correct 21 ms 7196 KB Output is correct
63 Correct 21 ms 7192 KB Output is correct
64 Correct 928 ms 14696 KB Output is correct
65 Correct 692 ms 14808 KB Output is correct
66 Correct 428 ms 11640 KB Output is correct
67 Correct 587 ms 14228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4017 ms 7128 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4093 ms 1872 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 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 14 ms 4768 KB Output is correct
37 Correct 22 ms 7200 KB Output is correct
38 Correct 21 ms 7208 KB Output is correct
39 Correct 21 ms 7248 KB Output is correct
40 Correct 21 ms 7196 KB Output is correct
41 Correct 22 ms 7200 KB Output is correct
42 Correct 19 ms 7204 KB Output is correct
43 Correct 153 ms 10900 KB Output is correct
44 Correct 64 ms 7968 KB Output is correct
45 Correct 31 ms 7240 KB Output is correct
46 Correct 20 ms 7204 KB Output is correct
47 Correct 29 ms 7196 KB Output is correct
48 Correct 22 ms 7216 KB Output is correct
49 Correct 37 ms 7220 KB Output is correct
50 Correct 23 ms 8512 KB Output is correct
51 Correct 28 ms 9932 KB Output is correct
52 Correct 24 ms 7240 KB Output is correct
53 Correct 21 ms 7240 KB Output is correct
54 Correct 22 ms 7216 KB Output is correct
55 Correct 41 ms 14612 KB Output is correct
56 Correct 37 ms 13968 KB Output is correct
57 Correct 24 ms 6976 KB Output is correct
58 Correct 29 ms 7228 KB Output is correct
59 Correct 22 ms 7196 KB Output is correct
60 Correct 20 ms 7248 KB Output is correct
61 Correct 22 ms 7220 KB Output is correct
62 Correct 21 ms 7196 KB Output is correct
63 Correct 21 ms 7192 KB Output is correct
64 Correct 928 ms 14696 KB Output is correct
65 Correct 692 ms 14808 KB Output is correct
66 Correct 428 ms 11640 KB Output is correct
67 Correct 587 ms 14228 KB Output is correct
68 Execution timed out 4017 ms 7128 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4057 ms 7900 KB Time limit exceeded
2 Halted 0 ms 0 KB -