Submission #732041

# Submission time Handle Problem Language Result Execution time Memory
732041 2023-04-28T09:41:58 Z alextodoran Radio Towers (IOI22_towers) C++17
37 / 100
4000 ms 19400 KB
/**
 _  _   __  _ _ _  _  _ _
 |a  ||t  ||o    d | |o  |
| __    _| | _ | __|  _ |
| __ |/_  | __  /__\ / _\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 100000;
const int E_MAX = 17;

int N;
int H[N_MAX];

int rmx[N_MAX][E_MAX];
int rmn[N_MAX][E_MAX];

int fmx (int i, int j) {
    return (H[i] >= H[j] ? i : j);
}
int fmn (int i, int j) {
    return (H[i] <= H[j] ? i : j);
}

int getmx (int l, int r) {
    int e = 31 - __builtin_clz(r - l + 1);
    return fmx(rmx[l][e], rmx[r - (1 << e) + 1][e]);
}
int getmn (int l, int r) {
    int e = 31 - __builtin_clz(r - l + 1);
    return fmn(rmn[l][e], rmn[r - (1 << e) + 1][e]);
}

int pref[N_MAX];

void init (int _N, vector <int> _H) {
    N = _N;
    for (int i = 0; i < N; i++) {
        H[i] = _H[i];
        rmx[i][0] = rmn[i][0] = i;
    }
    for (int e = 1; e < E_MAX; e++) {
        for (int i = 0; i + (1 << e) - 1 < N; i++) {
            rmx[i][e] = fmx(rmx[i][e - 1], rmx[i + (1 << (e - 1))][e - 1]);
            rmn[i][e] = fmn(rmn[i][e - 1], rmn[i + (1 << (e - 1))][e - 1]);
        }
    }
    for (int i = 1; i < N - 1; i++) {
        pref[i] = ((H[i - 1] < H[i] && H[i] < H[i + 1])
                || (H[i - 1] > H[i] && H[i] > H[i + 1]));
    }
    for (int i = 1; i < N; i++) {
        pref[i] += pref[i - 1];
    }
}

int max_towers (int L, int R, int D) {
    if (L > R) {
        return 0;
    }
    if (L == R) {
        return 1;
    }
    if (D == 1) {
        return ((R - L + 1) - (pref[R - 1] - pref[L]) - (H[L] > H[L + 1]) - (H[R] > H[R - 1]) + 1) / 2;
    }
    int K = getmx(L, R);
    int mxtL = max_towers(L, K - 1, D);
    int mxtR = max_towers(K + 1, R, D);
    return (H[getmn(L, K)] <= H[K] - D && H[getmn(K, R)] <= H[K] - D ? mxtL + mxtR : max(mxtL, mxtR));
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4072 ms 11324 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 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 592 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 592 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 19 ms 9872 KB Output is correct
37 Correct 34 ms 15160 KB Output is correct
38 Correct 39 ms 15040 KB Output is correct
39 Correct 33 ms 15092 KB Output is correct
40 Correct 32 ms 15048 KB Output is correct
41 Correct 35 ms 15040 KB Output is correct
42 Correct 35 ms 15140 KB Output is correct
43 Correct 35 ms 17080 KB Output is correct
44 Correct 37 ms 15408 KB Output is correct
45 Correct 33 ms 15160 KB Output is correct
46 Correct 34 ms 15160 KB Output is correct
47 Correct 43 ms 15152 KB Output is correct
48 Correct 33 ms 15048 KB Output is correct
49 Correct 32 ms 15032 KB Output is correct
50 Correct 35 ms 15144 KB Output is correct
51 Correct 43 ms 15048 KB Output is correct
52 Correct 36 ms 15276 KB Output is correct
53 Correct 31 ms 15176 KB Output is correct
54 Correct 33 ms 15128 KB Output is correct
55 Correct 32 ms 15148 KB Output is correct
56 Correct 32 ms 15144 KB Output is correct
57 Correct 47 ms 14632 KB Output is correct
58 Correct 37 ms 15040 KB Output is correct
59 Correct 35 ms 15048 KB Output is correct
60 Correct 38 ms 15156 KB Output is correct
61 Correct 38 ms 15048 KB Output is correct
62 Correct 36 ms 15036 KB Output is correct
63 Correct 36 ms 15280 KB Output is correct
64 Correct 37 ms 19400 KB Output is correct
65 Correct 38 ms 19368 KB Output is correct
66 Correct 38 ms 17624 KB Output is correct
67 Correct 39 ms 19124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 506 ms 15040 KB Output is correct
2 Correct 790 ms 15156 KB Output is correct
3 Correct 969 ms 15048 KB Output is correct
4 Correct 729 ms 15048 KB Output is correct
5 Correct 777 ms 15160 KB Output is correct
6 Correct 879 ms 15156 KB Output is correct
7 Correct 696 ms 15040 KB Output is correct
8 Correct 751 ms 15160 KB Output is correct
9 Correct 844 ms 15148 KB Output is correct
10 Correct 628 ms 15040 KB Output is correct
11 Correct 779 ms 15148 KB Output is correct
12 Correct 701 ms 15144 KB Output is correct
13 Correct 677 ms 15048 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 33 ms 15048 KB Output is correct
18 Correct 32 ms 15144 KB Output is correct
19 Correct 36 ms 15132 KB Output is correct
20 Correct 40 ms 15052 KB Output is correct
21 Correct 39 ms 15160 KB Output is correct
22 Correct 41 ms 15168 KB Output is correct
23 Correct 41 ms 15144 KB Output is correct
24 Correct 34 ms 15172 KB Output is correct
25 Correct 32 ms 15140 KB Output is correct
26 Correct 31 ms 15144 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4082 ms 3792 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 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 592 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 19 ms 9872 KB Output is correct
37 Correct 34 ms 15160 KB Output is correct
38 Correct 39 ms 15040 KB Output is correct
39 Correct 33 ms 15092 KB Output is correct
40 Correct 32 ms 15048 KB Output is correct
41 Correct 35 ms 15040 KB Output is correct
42 Correct 35 ms 15140 KB Output is correct
43 Correct 35 ms 17080 KB Output is correct
44 Correct 37 ms 15408 KB Output is correct
45 Correct 33 ms 15160 KB Output is correct
46 Correct 34 ms 15160 KB Output is correct
47 Correct 43 ms 15152 KB Output is correct
48 Correct 33 ms 15048 KB Output is correct
49 Correct 32 ms 15032 KB Output is correct
50 Correct 35 ms 15144 KB Output is correct
51 Correct 43 ms 15048 KB Output is correct
52 Correct 36 ms 15276 KB Output is correct
53 Correct 31 ms 15176 KB Output is correct
54 Correct 33 ms 15128 KB Output is correct
55 Correct 32 ms 15148 KB Output is correct
56 Correct 32 ms 15144 KB Output is correct
57 Correct 47 ms 14632 KB Output is correct
58 Correct 37 ms 15040 KB Output is correct
59 Correct 35 ms 15048 KB Output is correct
60 Correct 38 ms 15156 KB Output is correct
61 Correct 38 ms 15048 KB Output is correct
62 Correct 36 ms 15036 KB Output is correct
63 Correct 36 ms 15280 KB Output is correct
64 Correct 37 ms 19400 KB Output is correct
65 Correct 38 ms 19368 KB Output is correct
66 Correct 38 ms 17624 KB Output is correct
67 Correct 39 ms 19124 KB Output is correct
68 Correct 506 ms 15040 KB Output is correct
69 Correct 790 ms 15156 KB Output is correct
70 Correct 969 ms 15048 KB Output is correct
71 Correct 729 ms 15048 KB Output is correct
72 Correct 777 ms 15160 KB Output is correct
73 Correct 879 ms 15156 KB Output is correct
74 Correct 696 ms 15040 KB Output is correct
75 Correct 751 ms 15160 KB Output is correct
76 Correct 844 ms 15148 KB Output is correct
77 Correct 628 ms 15040 KB Output is correct
78 Correct 779 ms 15148 KB Output is correct
79 Correct 701 ms 15144 KB Output is correct
80 Correct 677 ms 15048 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 1 ms 592 KB Output is correct
83 Correct 1 ms 592 KB Output is correct
84 Correct 33 ms 15048 KB Output is correct
85 Correct 32 ms 15144 KB Output is correct
86 Correct 36 ms 15132 KB Output is correct
87 Correct 40 ms 15052 KB Output is correct
88 Correct 39 ms 15160 KB Output is correct
89 Correct 41 ms 15168 KB Output is correct
90 Correct 41 ms 15144 KB Output is correct
91 Correct 34 ms 15172 KB Output is correct
92 Correct 32 ms 15140 KB Output is correct
93 Correct 31 ms 15144 KB Output is correct
94 Correct 1 ms 592 KB Output is correct
95 Correct 1 ms 592 KB Output is correct
96 Correct 1 ms 592 KB Output is correct
97 Correct 1 ms 592 KB Output is correct
98 Correct 1 ms 592 KB Output is correct
99 Correct 1 ms 592 KB Output is correct
100 Correct 1 ms 592 KB Output is correct
101 Correct 1 ms 592 KB Output is correct
102 Correct 1 ms 592 KB Output is correct
103 Correct 1 ms 592 KB Output is correct
104 Execution timed out 4090 ms 13476 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4072 ms 11324 KB Time limit exceeded
2 Halted 0 ms 0 KB -