답안 #1056172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056172 2024-08-13T08:03:05 Z pawned 송신탑 (IOI22_towers) C++17
23 / 100
4000 ms 6132 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

#include "towers.h"

struct Segtree {	// point upd, range max
	int sz;
	vi vals;
	Segtree(int N) {
		sz = 1;
		while (sz < N)
			sz *= 2;
		vals = vi(2 * sz, 0);
	}
	void upd(int pos, int val, int id, int left, int right) {
		if (right - left == 1) {
			vals[id] = val;
			return;
		}
		int mid = (left + right) / 2;
		if (pos < mid)
			upd(pos, val, 2 * id + 1, left, mid);
		else
			upd(pos, val, 2 * id + 2, mid, right);
		vals[id] = max(vals[2 * id + 1], vals[2 * id + 2]);
	}
	void upd(int pos, int val) {
		upd(pos, val, 0, 0, sz);
	}
	int query(int qleft, int qright, int id, int left, int right) {
		if (qright <= left || right <= qleft)
			return 0;
		if (qleft <= left && right <= qright)
			return vals[id];
		int mid = (left + right) / 2;
		int s1 = query(qleft, qright, 2 * id + 1, left, mid);
		int s2 = query(qleft, qright, 2 * id + 2, mid, right);
		return max(s1, s2);
	}
	int query(int qleft, int qright) {
		return query(qleft, qright, 0, 0, sz);
	}
};

int N;
vi H;
int maxv = -1;
int maxp = -1;

void init(int N_g, vi H_g) {
	N = N_g;
	H = H_g;

}

int max_towers(int L, int R, int D) {
	int K = R - L + 1;
	vi h;
	for (int j = L; j <= R; j++) {
		h.pb(H[j]);
	}
/*	cout<<"h: ";
	for (int x : h)
		cout<<x<<" ";
	cout<<endl;*/
	Segtree st(K);
	for (int j = 0; j < K; j++) {
		st.upd(j, h[j]);
	}
	vector<ii> allp;	// {height, pos}
	for (int j = 0; j < K; j++) {
		allp.pb({h[j], j});
	}
	sort(allp.begin(), allp.end());
	vi order;
	for (int j = 0; j < K; j++) {
		order.pb(allp[j].se);
	}
	int total = 0;
	vector<bool> used(K, false);
	set<int> allu;
	for (int j = 0; j < K; j++) {	// see if can use order[j]
//		cout<<"at "<<j<<endl;
		bool can = true;
		auto it = allu.lower_bound(order[j]);
		if (it != allu.begin()) {	// has to the left
			auto it2 = it;
			it2--;
			int lp = *it2;	// left position
			int maxr = st.query(lp + 1, order[j]);
			if (h[order[j]] > maxr - D)
				can = false;
		}
		if (it != allu.end()) {	// has to the right
			int rp = *it;
			int maxr = st.query(order[j] + 1, rp);
			if (h[order[j]] > maxr - D)
				can = false;
		}
		if (can) {
//			cout<<"can use "<<order[j]<<endl;
			total++;
			used[order[j]] = true;
			allu.insert(order[j]);
		}
	}
/*	cout<<"used: ";
	for (bool b : used)
		cout<<b<<" ";
	cout<<endl;*/
	return total;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4030 ms 2820 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 516 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 516 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 12 ms 1624 KB Output is correct
37 Correct 25 ms 2512 KB Output is correct
38 Correct 18 ms 1488 KB Output is correct
39 Correct 24 ms 2000 KB Output is correct
40 Correct 13 ms 1744 KB Output is correct
41 Correct 45 ms 4268 KB Output is correct
42 Correct 7 ms 1368 KB Output is correct
43 Correct 15 ms 2716 KB Output is correct
44 Correct 8 ms 1596 KB Output is correct
45 Correct 8 ms 1368 KB Output is correct
46 Correct 7 ms 1608 KB Output is correct
47 Correct 25 ms 2768 KB Output is correct
48 Correct 16 ms 2256 KB Output is correct
49 Correct 10 ms 1572 KB Output is correct
50 Correct 12 ms 1976 KB Output is correct
51 Correct 14 ms 2700 KB Output is correct
52 Correct 56 ms 5312 KB Output is correct
53 Correct 67 ms 6132 KB Output is correct
54 Correct 64 ms 6084 KB Output is correct
55 Correct 23 ms 4300 KB Output is correct
56 Correct 29 ms 4348 KB Output is correct
57 Correct 56 ms 4060 KB Output is correct
58 Correct 62 ms 4548 KB Output is correct
59 Correct 55 ms 4804 KB Output is correct
60 Correct 58 ms 6092 KB Output is correct
61 Correct 58 ms 5572 KB Output is correct
62 Correct 65 ms 5060 KB Output is correct
63 Correct 59 ms 5828 KB Output is correct
64 Correct 23 ms 4300 KB Output is correct
65 Correct 30 ms 4172 KB Output is correct
66 Correct 34 ms 4300 KB Output is correct
67 Correct 23 ms 4300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4022 ms 5696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 1912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 516 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 12 ms 1624 KB Output is correct
37 Correct 25 ms 2512 KB Output is correct
38 Correct 18 ms 1488 KB Output is correct
39 Correct 24 ms 2000 KB Output is correct
40 Correct 13 ms 1744 KB Output is correct
41 Correct 45 ms 4268 KB Output is correct
42 Correct 7 ms 1368 KB Output is correct
43 Correct 15 ms 2716 KB Output is correct
44 Correct 8 ms 1596 KB Output is correct
45 Correct 8 ms 1368 KB Output is correct
46 Correct 7 ms 1608 KB Output is correct
47 Correct 25 ms 2768 KB Output is correct
48 Correct 16 ms 2256 KB Output is correct
49 Correct 10 ms 1572 KB Output is correct
50 Correct 12 ms 1976 KB Output is correct
51 Correct 14 ms 2700 KB Output is correct
52 Correct 56 ms 5312 KB Output is correct
53 Correct 67 ms 6132 KB Output is correct
54 Correct 64 ms 6084 KB Output is correct
55 Correct 23 ms 4300 KB Output is correct
56 Correct 29 ms 4348 KB Output is correct
57 Correct 56 ms 4060 KB Output is correct
58 Correct 62 ms 4548 KB Output is correct
59 Correct 55 ms 4804 KB Output is correct
60 Correct 58 ms 6092 KB Output is correct
61 Correct 58 ms 5572 KB Output is correct
62 Correct 65 ms 5060 KB Output is correct
63 Correct 59 ms 5828 KB Output is correct
64 Correct 23 ms 4300 KB Output is correct
65 Correct 30 ms 4172 KB Output is correct
66 Correct 34 ms 4300 KB Output is correct
67 Correct 23 ms 4300 KB Output is correct
68 Execution timed out 4022 ms 5696 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4030 ms 2820 KB Time limit exceeded
2 Halted 0 ms 0 KB -