답안 #775870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775870 2023-07-07T05:38:23 Z SanguineChameleon 송신탑 (IOI22_towers) C++17
41 / 100
4000 ms 13736 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

const int maxN = 1e5 + 20;
bool sub1;
vector<int> events[maxN];
int firstL[maxN];
int firstR[maxN];
int dp[maxN];
int bit[maxN];
int cnt_min[maxN];
int H[maxN];
int N;
int max_id;

void init(int _N, vector<int> _H) {
	N = _N;
	for (int i = 0; i < N; i++) {
		H[i] = _H[i];
	}
	max_id = 0;
	for (int i = 0; i < N; i++) {
		if (H[i] > H[max_id]) {
			max_id = i;
		}
	}
	sub1 = true;
	for (int i = 0; i < max_id; i++) {
		sub1 &= H[i] < H[i + 1];
	}
	for (int i = max_id; i + 1 < N; i++) {
		sub1 &= H[i] > H[i + 1];
	}
	for (int i = 1; i < N - 1; i++) {
		cnt_min[i] = cnt_min[i - 1] + (H[i] < H[i - 1] && H[i] < H[i + 1]);
	}
}

void update(int pos, int val) {
	for (int i = pos; i <= N; i += i & (-i)) {
		bit[i] = max(bit[i], val);
	}
}

int get(int pos) {
	int res = 0;
	for (int i = pos; i > 0; i -= i & (-i)) {
		res = max(res, bit[i]);
	}
	return res;
}

int max_towers(int L, int R, int D) {
	if (L == R) {
		return 1;
	}
	if (sub1) {
		if (R <= max_id) {
			return 1;
		}
		else if (L >= max_id) {
			return 1;
		}
		else {
			return 1 + (H[max_id] >= max(H[L], H[R]) + D);
		}
	}
	if (D == 1) {
		return cnt_min[R - 1] - cnt_min[L] + (H[L] < H[L + 1]) + (H[R] < H[R - 1]);
	}
	for (int i = L; i <= R; i++) {
		firstL[i] = L - 1;
		firstR[i] = R + 1;
		for (int j = i; j <= R; j++) {
			if (H[j] >= H[i] + D) {
				firstR[i] = j;
				break;
			}
		}
		for (int j = i; j >= L; j--) {
			if (H[j] >= H[i] + D) {
				firstL[i] = j;
				break;
			}
		}
		if (firstR[i] < R) {
			events[firstR[i] + 1].push_back(i);
		}
	}
	int res = 0;
	for (int i = L; i <= R; i++) {
		for (auto id: events[i]) {
			update(id + 1, dp[id]);
		}
		dp[i] = 1 + (firstL[i] > L ? get(firstL[i]) : 0);
		res = max(res, dp[i]);
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 3540 KB Output is correct
2 Correct 654 ms 4192 KB Output is correct
3 Correct 537 ms 4168 KB Output is correct
4 Correct 602 ms 4184 KB Output is correct
5 Correct 617 ms 4192 KB Output is correct
6 Correct 597 ms 4224 KB Output is correct
7 Correct 513 ms 4180 KB Output is correct
8 Correct 1 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 1 ms 2660 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 1 ms 2640 KB Output is correct
11 Correct 1 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 1 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 2 ms 2640 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 1 ms 2640 KB Output is correct
22 Correct 1 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 1 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 3 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 3 ms 2640 KB Output is correct
30 Correct 3 ms 2640 KB Output is correct
31 Correct 3 ms 2640 KB Output is correct
32 Correct 1 ms 2640 KB Output is correct
33 Correct 1 ms 2640 KB Output is correct
34 Correct 3 ms 2700 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 1 ms 2660 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 1 ms 2640 KB Output is correct
11 Correct 1 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 1 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 2 ms 2640 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 1 ms 2640 KB Output is correct
22 Correct 1 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 1 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 3 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 3 ms 2640 KB Output is correct
30 Correct 3 ms 2640 KB Output is correct
31 Correct 3 ms 2640 KB Output is correct
32 Correct 1 ms 2640 KB Output is correct
33 Correct 1 ms 2640 KB Output is correct
34 Correct 3 ms 2700 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 18 ms 3932 KB Output is correct
37 Correct 319 ms 4428 KB Output is correct
38 Correct 33 ms 4188 KB Output is correct
39 Correct 319 ms 4352 KB Output is correct
40 Correct 28 ms 4164 KB Output is correct
41 Correct 1173 ms 5824 KB Output is correct
42 Correct 11 ms 4176 KB Output is correct
43 Correct 10 ms 4184 KB Output is correct
44 Correct 18 ms 4176 KB Output is correct
45 Correct 12 ms 4096 KB Output is correct
46 Correct 12 ms 4176 KB Output is correct
47 Correct 10 ms 4184 KB Output is correct
48 Correct 16 ms 4200 KB Output is correct
49 Correct 10 ms 4192 KB Output is correct
50 Correct 10 ms 4180 KB Output is correct
51 Correct 10 ms 4200 KB Output is correct
52 Correct 11 ms 4168 KB Output is correct
53 Correct 10 ms 4176 KB Output is correct
54 Correct 18 ms 4196 KB Output is correct
55 Correct 10 ms 4172 KB Output is correct
56 Correct 10 ms 4176 KB Output is correct
57 Correct 1937 ms 5756 KB Output is correct
58 Correct 1444 ms 6184 KB Output is correct
59 Correct 814 ms 6556 KB Output is correct
60 Correct 60 ms 6932 KB Output is correct
61 Correct 812 ms 6736 KB Output is correct
62 Correct 1409 ms 6496 KB Output is correct
63 Correct 744 ms 6856 KB Output is correct
64 Correct 17 ms 4168 KB Output is correct
65 Correct 13 ms 4304 KB Output is correct
66 Correct 1949 ms 6076 KB Output is correct
67 Correct 2778 ms 4968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 533 ms 4192 KB Output is correct
2 Correct 764 ms 4084 KB Output is correct
3 Correct 715 ms 4180 KB Output is correct
4 Correct 464 ms 4176 KB Output is correct
5 Correct 566 ms 4176 KB Output is correct
6 Correct 648 ms 4180 KB Output is correct
7 Correct 681 ms 4140 KB Output is correct
8 Correct 683 ms 4192 KB Output is correct
9 Correct 726 ms 4176 KB Output is correct
10 Correct 624 ms 4176 KB Output is correct
11 Correct 694 ms 4176 KB Output is correct
12 Correct 713 ms 4176 KB Output is correct
13 Correct 638 ms 4180 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 1 ms 2640 KB Output is correct
17 Correct 11 ms 4176 KB Output is correct
18 Correct 18 ms 4200 KB Output is correct
19 Correct 10 ms 4168 KB Output is correct
20 Correct 10 ms 4176 KB Output is correct
21 Correct 17 ms 4176 KB Output is correct
22 Correct 11 ms 4196 KB Output is correct
23 Correct 11 ms 4176 KB Output is correct
24 Correct 13 ms 4192 KB Output is correct
25 Correct 10 ms 4176 KB Output is correct
26 Correct 10 ms 4180 KB Output is correct
27 Correct 1 ms 2640 KB Output is correct
28 Correct 1 ms 2584 KB Output is correct
29 Correct 2 ms 2676 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 1 ms 2640 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 1 ms 2640 KB Output is correct
34 Correct 1 ms 2640 KB Output is correct
35 Correct 1 ms 2640 KB Output is correct
36 Correct 2 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 8196 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 1 ms 2660 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 1 ms 2640 KB Output is correct
11 Correct 1 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 1 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 2 ms 2640 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 1 ms 2640 KB Output is correct
22 Correct 1 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 1 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 3 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 3 ms 2640 KB Output is correct
30 Correct 3 ms 2640 KB Output is correct
31 Correct 3 ms 2640 KB Output is correct
32 Correct 1 ms 2640 KB Output is correct
33 Correct 1 ms 2640 KB Output is correct
34 Correct 3 ms 2700 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 18 ms 3932 KB Output is correct
37 Correct 319 ms 4428 KB Output is correct
38 Correct 33 ms 4188 KB Output is correct
39 Correct 319 ms 4352 KB Output is correct
40 Correct 28 ms 4164 KB Output is correct
41 Correct 1173 ms 5824 KB Output is correct
42 Correct 11 ms 4176 KB Output is correct
43 Correct 10 ms 4184 KB Output is correct
44 Correct 18 ms 4176 KB Output is correct
45 Correct 12 ms 4096 KB Output is correct
46 Correct 12 ms 4176 KB Output is correct
47 Correct 10 ms 4184 KB Output is correct
48 Correct 16 ms 4200 KB Output is correct
49 Correct 10 ms 4192 KB Output is correct
50 Correct 10 ms 4180 KB Output is correct
51 Correct 10 ms 4200 KB Output is correct
52 Correct 11 ms 4168 KB Output is correct
53 Correct 10 ms 4176 KB Output is correct
54 Correct 18 ms 4196 KB Output is correct
55 Correct 10 ms 4172 KB Output is correct
56 Correct 10 ms 4176 KB Output is correct
57 Correct 1937 ms 5756 KB Output is correct
58 Correct 1444 ms 6184 KB Output is correct
59 Correct 814 ms 6556 KB Output is correct
60 Correct 60 ms 6932 KB Output is correct
61 Correct 812 ms 6736 KB Output is correct
62 Correct 1409 ms 6496 KB Output is correct
63 Correct 744 ms 6856 KB Output is correct
64 Correct 17 ms 4168 KB Output is correct
65 Correct 13 ms 4304 KB Output is correct
66 Correct 1949 ms 6076 KB Output is correct
67 Correct 2778 ms 4968 KB Output is correct
68 Correct 533 ms 4192 KB Output is correct
69 Correct 764 ms 4084 KB Output is correct
70 Correct 715 ms 4180 KB Output is correct
71 Correct 464 ms 4176 KB Output is correct
72 Correct 566 ms 4176 KB Output is correct
73 Correct 648 ms 4180 KB Output is correct
74 Correct 681 ms 4140 KB Output is correct
75 Correct 683 ms 4192 KB Output is correct
76 Correct 726 ms 4176 KB Output is correct
77 Correct 624 ms 4176 KB Output is correct
78 Correct 694 ms 4176 KB Output is correct
79 Correct 713 ms 4176 KB Output is correct
80 Correct 638 ms 4180 KB Output is correct
81 Correct 2 ms 2640 KB Output is correct
82 Correct 2 ms 2640 KB Output is correct
83 Correct 1 ms 2640 KB Output is correct
84 Correct 11 ms 4176 KB Output is correct
85 Correct 18 ms 4200 KB Output is correct
86 Correct 10 ms 4168 KB Output is correct
87 Correct 10 ms 4176 KB Output is correct
88 Correct 17 ms 4176 KB Output is correct
89 Correct 11 ms 4196 KB Output is correct
90 Correct 11 ms 4176 KB Output is correct
91 Correct 13 ms 4192 KB Output is correct
92 Correct 10 ms 4176 KB Output is correct
93 Correct 10 ms 4180 KB Output is correct
94 Correct 1 ms 2640 KB Output is correct
95 Correct 1 ms 2584 KB Output is correct
96 Correct 2 ms 2676 KB Output is correct
97 Correct 2 ms 2640 KB Output is correct
98 Correct 1 ms 2640 KB Output is correct
99 Correct 2 ms 2640 KB Output is correct
100 Correct 1 ms 2640 KB Output is correct
101 Correct 1 ms 2640 KB Output is correct
102 Correct 1 ms 2640 KB Output is correct
103 Correct 2 ms 2640 KB Output is correct
104 Execution timed out 4091 ms 13736 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 3540 KB Output is correct
2 Correct 654 ms 4192 KB Output is correct
3 Correct 537 ms 4168 KB Output is correct
4 Correct 602 ms 4184 KB Output is correct
5 Correct 617 ms 4192 KB Output is correct
6 Correct 597 ms 4224 KB Output is correct
7 Correct 513 ms 4180 KB Output is correct
8 Correct 1 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 1 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 1 ms 2660 KB Output is correct
19 Correct 2 ms 2640 KB Output is correct
20 Correct 1 ms 2640 KB Output is correct
21 Correct 1 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 1 ms 2640 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 1 ms 2640 KB Output is correct
32 Correct 1 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 1 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 3 ms 2640 KB Output is correct
37 Correct 2 ms 2640 KB Output is correct
38 Correct 2 ms 2640 KB Output is correct
39 Correct 3 ms 2640 KB Output is correct
40 Correct 3 ms 2640 KB Output is correct
41 Correct 3 ms 2640 KB Output is correct
42 Correct 1 ms 2640 KB Output is correct
43 Correct 1 ms 2640 KB Output is correct
44 Correct 3 ms 2700 KB Output is correct
45 Correct 2 ms 2640 KB Output is correct
46 Correct 18 ms 3932 KB Output is correct
47 Correct 319 ms 4428 KB Output is correct
48 Correct 33 ms 4188 KB Output is correct
49 Correct 319 ms 4352 KB Output is correct
50 Correct 28 ms 4164 KB Output is correct
51 Correct 1173 ms 5824 KB Output is correct
52 Correct 11 ms 4176 KB Output is correct
53 Correct 10 ms 4184 KB Output is correct
54 Correct 18 ms 4176 KB Output is correct
55 Correct 12 ms 4096 KB Output is correct
56 Correct 12 ms 4176 KB Output is correct
57 Correct 10 ms 4184 KB Output is correct
58 Correct 16 ms 4200 KB Output is correct
59 Correct 10 ms 4192 KB Output is correct
60 Correct 10 ms 4180 KB Output is correct
61 Correct 10 ms 4200 KB Output is correct
62 Correct 11 ms 4168 KB Output is correct
63 Correct 10 ms 4176 KB Output is correct
64 Correct 18 ms 4196 KB Output is correct
65 Correct 10 ms 4172 KB Output is correct
66 Correct 10 ms 4176 KB Output is correct
67 Correct 1937 ms 5756 KB Output is correct
68 Correct 1444 ms 6184 KB Output is correct
69 Correct 814 ms 6556 KB Output is correct
70 Correct 60 ms 6932 KB Output is correct
71 Correct 812 ms 6736 KB Output is correct
72 Correct 1409 ms 6496 KB Output is correct
73 Correct 744 ms 6856 KB Output is correct
74 Correct 17 ms 4168 KB Output is correct
75 Correct 13 ms 4304 KB Output is correct
76 Correct 1949 ms 6076 KB Output is correct
77 Correct 2778 ms 4968 KB Output is correct
78 Correct 533 ms 4192 KB Output is correct
79 Correct 764 ms 4084 KB Output is correct
80 Correct 715 ms 4180 KB Output is correct
81 Correct 464 ms 4176 KB Output is correct
82 Correct 566 ms 4176 KB Output is correct
83 Correct 648 ms 4180 KB Output is correct
84 Correct 681 ms 4140 KB Output is correct
85 Correct 683 ms 4192 KB Output is correct
86 Correct 726 ms 4176 KB Output is correct
87 Correct 624 ms 4176 KB Output is correct
88 Correct 694 ms 4176 KB Output is correct
89 Correct 713 ms 4176 KB Output is correct
90 Correct 638 ms 4180 KB Output is correct
91 Correct 2 ms 2640 KB Output is correct
92 Correct 2 ms 2640 KB Output is correct
93 Correct 1 ms 2640 KB Output is correct
94 Correct 11 ms 4176 KB Output is correct
95 Correct 18 ms 4200 KB Output is correct
96 Correct 10 ms 4168 KB Output is correct
97 Correct 10 ms 4176 KB Output is correct
98 Correct 17 ms 4176 KB Output is correct
99 Correct 11 ms 4196 KB Output is correct
100 Correct 11 ms 4176 KB Output is correct
101 Correct 13 ms 4192 KB Output is correct
102 Correct 10 ms 4176 KB Output is correct
103 Correct 10 ms 4180 KB Output is correct
104 Correct 1 ms 2640 KB Output is correct
105 Correct 1 ms 2584 KB Output is correct
106 Correct 2 ms 2676 KB Output is correct
107 Correct 2 ms 2640 KB Output is correct
108 Correct 1 ms 2640 KB Output is correct
109 Correct 2 ms 2640 KB Output is correct
110 Correct 1 ms 2640 KB Output is correct
111 Correct 1 ms 2640 KB Output is correct
112 Correct 1 ms 2640 KB Output is correct
113 Correct 2 ms 2640 KB Output is correct
114 Execution timed out 4051 ms 8196 KB Time limit exceeded
115 Halted 0 ms 0 KB -