Submission #826465

# Submission time Handle Problem Language Result Execution time Memory
826465 2023-08-15T15:35:10 Z esomer Radio Towers (IOI22_towers) C++17
27 / 100
4000 ms 23032 KB
#include <bits/stdc++.h>
#include "towers.h"

using namespace std;

int N, spec;
vector<int> H, lw;
vector<vector<pair<int, int>>> mn;

pair<int, int> get_mx(int l, int r){
	int k = lw[r - l + 1];
	return max(mn[k][r], mn[k][l + (1 << k) - 1]);
}

void init(int n, vector<int> H1) {
	N = n;
	H = H1;
	spec = 0;
	bool asc = 1;
	for(int i = 1; i < N; i++){
		if(spec == -1) break;
		if(H[i] > H[i-1]){
			if(asc) spec = i;
			else spec = -1;
		}else{
			asc = 0;
		}
	}
	lw.resize(N+1);
	mn.assign(20, vector<pair<int, int>>(N));
	for(int k = 0; k < 20; k++){
		for(int i = 0; i < N; i++){
			if(k == 0) mn[k][i] = {H[i], i};
			else{
				if(i - (1 << (k-1)) < 0) mn[k][i] = mn[k-1][i];
				else{
					mn[k][i] = max(mn[k-1][i], mn[k-1][i - (1 << (k-1))]);
				}
			}
		}
	}
	int pw = 0;
	int curr = 2;
	for(int i = 1; i <= N; i++){
		if(i == curr){
			pw++; curr *= 2;
		}
		lw[i] = pw;
	}
}

pair<int, int> dnc(int L, int R, int D) {
	if(L == R) {
		return {H[L], 1};
	}else if(L > R){
		return {2e9, 0};
	}
	pair<int, int> pr = get_mx(L, R);
	int mx = pr.first;
	int ind = pr.second;
	pair<int, int> ans1 = dnc(ind + 1, R, D);
	pair<int, int> ans2 = dnc(L, ind - 1, D);
	if(ans1.first <= mx - D && ans2.first <= mx - D) return {ans1.first, ans1.second + ans2.second};
	else return min(ans1, ans2);
}

int max_towers(int L, int R, int D) {
	if(spec == -1) return dnc(L, R, D).second;
	else{
		int ans = 1;
		if(L < spec && R > spec && H[L] <= H[spec] - D && H[R] <= H[spec] - D) ans++;
		return ans;
	}
}

// int main() {
//   int N, Q;
//   assert(2 == scanf("%d %d", &N, &Q));
//   std::vector<int> H(N);
//   for (int i = 0; i < N; ++i) {
//     assert(1 == scanf("%d", &H[i]));
//   }
//   init(N, H);
//   for (int i = 0; i < Q; ++i) {
//     int L, R, D;
//     assert(3 == scanf("%d %d %d", &L, &R, &D));
//     printf("%d\n", max_towers(L, R, D));
//   }
//   return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 370 ms 11084 KB Output is correct
2 Correct 704 ms 18332 KB Output is correct
3 Correct 588 ms 18324 KB Output is correct
4 Correct 772 ms 18320 KB Output is correct
5 Correct 753 ms 18344 KB Output is correct
6 Correct 679 ms 18328 KB Output is correct
7 Correct 644 ms 18320 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 620 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 636 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 564 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 664 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 640 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 640 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 768 KB Output is correct
25 Correct 1 ms 376 KB Output is correct
26 Correct 1 ms 656 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 624 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 652 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 720 KB Output is correct
35 Correct 1 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 620 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 636 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 564 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 664 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 640 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 640 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 768 KB Output is correct
25 Correct 1 ms 376 KB Output is correct
26 Correct 1 ms 656 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 624 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 652 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 720 KB Output is correct
35 Correct 1 ms 720 KB Output is correct
36 Correct 14 ms 12100 KB Output is correct
37 Correct 24 ms 18328 KB Output is correct
38 Correct 25 ms 18336 KB Output is correct
39 Correct 23 ms 18328 KB Output is correct
40 Correct 20 ms 18340 KB Output is correct
41 Correct 35 ms 18368 KB Output is correct
42 Correct 25 ms 18320 KB Output is correct
43 Correct 32 ms 18232 KB Output is correct
44 Correct 21 ms 18320 KB Output is correct
45 Correct 25 ms 18332 KB Output is correct
46 Correct 38 ms 18352 KB Output is correct
47 Correct 43 ms 18320 KB Output is correct
48 Correct 30 ms 18272 KB Output is correct
49 Correct 27 ms 18288 KB Output is correct
50 Correct 28 ms 18244 KB Output is correct
51 Correct 31 ms 19596 KB Output is correct
52 Correct 31 ms 18380 KB Output is correct
53 Correct 30 ms 18332 KB Output is correct
54 Correct 31 ms 18260 KB Output is correct
55 Correct 30 ms 18232 KB Output is correct
56 Correct 29 ms 22792 KB Output is correct
57 Correct 34 ms 17684 KB Output is correct
58 Correct 28 ms 18336 KB Output is correct
59 Correct 33 ms 18300 KB Output is correct
60 Correct 33 ms 18328 KB Output is correct
61 Correct 36 ms 18332 KB Output is correct
62 Correct 39 ms 18332 KB Output is correct
63 Correct 29 ms 18340 KB Output is correct
64 Correct 21 ms 18248 KB Output is correct
65 Correct 25 ms 18352 KB Output is correct
66 Correct 31 ms 20960 KB Output is correct
67 Correct 32 ms 23032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4075 ms 18064 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4080 ms 4560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 620 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 636 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 564 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 664 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 640 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 640 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 768 KB Output is correct
25 Correct 1 ms 376 KB Output is correct
26 Correct 1 ms 656 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 624 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 652 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 720 KB Output is correct
35 Correct 1 ms 720 KB Output is correct
36 Correct 14 ms 12100 KB Output is correct
37 Correct 24 ms 18328 KB Output is correct
38 Correct 25 ms 18336 KB Output is correct
39 Correct 23 ms 18328 KB Output is correct
40 Correct 20 ms 18340 KB Output is correct
41 Correct 35 ms 18368 KB Output is correct
42 Correct 25 ms 18320 KB Output is correct
43 Correct 32 ms 18232 KB Output is correct
44 Correct 21 ms 18320 KB Output is correct
45 Correct 25 ms 18332 KB Output is correct
46 Correct 38 ms 18352 KB Output is correct
47 Correct 43 ms 18320 KB Output is correct
48 Correct 30 ms 18272 KB Output is correct
49 Correct 27 ms 18288 KB Output is correct
50 Correct 28 ms 18244 KB Output is correct
51 Correct 31 ms 19596 KB Output is correct
52 Correct 31 ms 18380 KB Output is correct
53 Correct 30 ms 18332 KB Output is correct
54 Correct 31 ms 18260 KB Output is correct
55 Correct 30 ms 18232 KB Output is correct
56 Correct 29 ms 22792 KB Output is correct
57 Correct 34 ms 17684 KB Output is correct
58 Correct 28 ms 18336 KB Output is correct
59 Correct 33 ms 18300 KB Output is correct
60 Correct 33 ms 18328 KB Output is correct
61 Correct 36 ms 18332 KB Output is correct
62 Correct 39 ms 18332 KB Output is correct
63 Correct 29 ms 18340 KB Output is correct
64 Correct 21 ms 18248 KB Output is correct
65 Correct 25 ms 18352 KB Output is correct
66 Correct 31 ms 20960 KB Output is correct
67 Correct 32 ms 23032 KB Output is correct
68 Execution timed out 4075 ms 18064 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 370 ms 11084 KB Output is correct
2 Correct 704 ms 18332 KB Output is correct
3 Correct 588 ms 18324 KB Output is correct
4 Correct 772 ms 18320 KB Output is correct
5 Correct 753 ms 18344 KB Output is correct
6 Correct 679 ms 18328 KB Output is correct
7 Correct 644 ms 18320 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 376 KB Output is correct
12 Correct 1 ms 620 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 636 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 564 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 664 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 1 ms 640 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 592 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 640 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 768 KB Output is correct
35 Correct 1 ms 376 KB Output is correct
36 Correct 1 ms 656 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 592 KB Output is correct
39 Correct 1 ms 592 KB Output is correct
40 Correct 1 ms 624 KB Output is correct
41 Correct 1 ms 592 KB Output is correct
42 Correct 1 ms 652 KB Output is correct
43 Correct 1 ms 592 KB Output is correct
44 Correct 1 ms 720 KB Output is correct
45 Correct 1 ms 720 KB Output is correct
46 Correct 14 ms 12100 KB Output is correct
47 Correct 24 ms 18328 KB Output is correct
48 Correct 25 ms 18336 KB Output is correct
49 Correct 23 ms 18328 KB Output is correct
50 Correct 20 ms 18340 KB Output is correct
51 Correct 35 ms 18368 KB Output is correct
52 Correct 25 ms 18320 KB Output is correct
53 Correct 32 ms 18232 KB Output is correct
54 Correct 21 ms 18320 KB Output is correct
55 Correct 25 ms 18332 KB Output is correct
56 Correct 38 ms 18352 KB Output is correct
57 Correct 43 ms 18320 KB Output is correct
58 Correct 30 ms 18272 KB Output is correct
59 Correct 27 ms 18288 KB Output is correct
60 Correct 28 ms 18244 KB Output is correct
61 Correct 31 ms 19596 KB Output is correct
62 Correct 31 ms 18380 KB Output is correct
63 Correct 30 ms 18332 KB Output is correct
64 Correct 31 ms 18260 KB Output is correct
65 Correct 30 ms 18232 KB Output is correct
66 Correct 29 ms 22792 KB Output is correct
67 Correct 34 ms 17684 KB Output is correct
68 Correct 28 ms 18336 KB Output is correct
69 Correct 33 ms 18300 KB Output is correct
70 Correct 33 ms 18328 KB Output is correct
71 Correct 36 ms 18332 KB Output is correct
72 Correct 39 ms 18332 KB Output is correct
73 Correct 29 ms 18340 KB Output is correct
74 Correct 21 ms 18248 KB Output is correct
75 Correct 25 ms 18352 KB Output is correct
76 Correct 31 ms 20960 KB Output is correct
77 Correct 32 ms 23032 KB Output is correct
78 Execution timed out 4075 ms 18064 KB Time limit exceeded
79 Halted 0 ms 0 KB -