Submission #1069946

# Submission time Handle Problem Language Result Execution time Memory
1069946 2024-08-22T10:26:39 Z Arapak Radio Towers (IOI22_towers) C++17
11 / 100
4000 ms 6932 KB
#include "towers.h"
#include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

#ifdef DEBUG
auto& operator<<(auto &os, const pair<auto,auto> &p) {
	return os<<"("<<p.first<<", "<<p.second<<")";
}
auto& operator<<(auto &os, const auto &v) {
	os<<"{";
	for(auto it=begin(v);it!=end(v);++it) {
		if(it != begin(v)) os<<", ";
		os<<(*it);
	}
	return os<<"}";
}

void dbg_out(auto... x) {
	((cerr<<' '<<x), ...) << endl;
}
#define dbg(x...) cerr<<"("<<#x<<"):", dbg_out(x);
#else
#define dbg(...)
#endif

const int inf = 1e9 + 7;

int n, root;
vi h;
vi L, R, siz;

int get_max(int l, int r) {
	int maxi = l;
	rep(i,l+1,r)
		if(h[i] > h[maxi])
			maxi = i;
	return maxi;
}

int build_tree(int l, int r) {
	if(l == r) return -1;
	if(l+1 == r) {
		siz[l] = 1;
		return l;
	}
	int index = get_max(l, r);
	L[index] = build_tree(l, index);
	R[index] = build_tree(index+1, r);
	siz[index] = (L[index] == -1 ? 0 : siz[L[index]]) 
				+(R[index] == -1 ? 0 : siz[R[index]]);
	return index;
}

void init(int N, vi H) {
	n = N;
	h = H;
	L.resize(n);
	R.resize(n);
	siz.assign(n, 0);
	root = build_tree(0, n);
	dbg(root);
	dbg(L);
	dbg(R);
}

int solve(int v, int l, int r, int a, int b, int d, int maxi) {
	if(l == r || r <= a || b <= l) return 0;
	dbg(v, l, r, a, b, d, maxi);
	if(l+1 == r) return h[v] <= maxi;
	int res = 0;
	if(L[v] == -1 || v < a)
		res += solve(R[v], v+1, r, a, b, d, maxi);
	else if(R[v] == -1 || v >= b)
		res += solve(L[v], l, v, a, b, d, maxi);
	else {
		res += solve(L[v], l  , v, a, b, d, min(maxi, h[v] - d));
		res += solve(R[v], v+1, r, a, b, d, min(maxi, h[v] - d));
	
		res = max(res, solve(R[v], v+1, r, a, b, d, maxi));
		res = max(res, solve(L[v], l, v, a, b, d, maxi));
	}
	if(res == 0 && (a <= v && v < b && h[v] <= maxi))
		return 1;
	return res;
}

int max_towers(int L, int R, int D) {
	int res = solve(root, 0, n, L, R+1, D, inf);
	return res == 0 ? 1 : res;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4003 ms 6932 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Correct 25 ms 340 KB Output is correct
4 Correct 577 ms 448 KB Output is correct
5 Correct 123 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 30 ms 452 KB Output is correct
8 Correct 6 ms 600 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 5 ms 476 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 5 ms 600 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 105 ms 452 KB Output is correct
17 Correct 9 ms 344 KB Output is correct
18 Correct 6 ms 600 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 101 ms 468 KB Output is correct
21 Correct 389 ms 344 KB Output is correct
22 Correct 168 ms 344 KB Output is correct
23 Correct 6 ms 600 KB Output is correct
24 Correct 5 ms 600 KB Output is correct
25 Correct 52 ms 344 KB Output is correct
26 Correct 71 ms 344 KB Output is correct
27 Correct 605 ms 344 KB Output is correct
28 Correct 716 ms 452 KB Output is correct
29 Correct 707 ms 344 KB Output is correct
30 Correct 2331 ms 452 KB Output is correct
31 Correct 360 ms 344 KB Output is correct
32 Correct 6 ms 600 KB Output is correct
33 Correct 6 ms 600 KB Output is correct
34 Correct 5 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Correct 25 ms 340 KB Output is correct
4 Correct 577 ms 448 KB Output is correct
5 Correct 123 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 30 ms 452 KB Output is correct
8 Correct 6 ms 600 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 5 ms 476 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 5 ms 600 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 105 ms 452 KB Output is correct
17 Correct 9 ms 344 KB Output is correct
18 Correct 6 ms 600 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 101 ms 468 KB Output is correct
21 Correct 389 ms 344 KB Output is correct
22 Correct 168 ms 344 KB Output is correct
23 Correct 6 ms 600 KB Output is correct
24 Correct 5 ms 600 KB Output is correct
25 Correct 52 ms 344 KB Output is correct
26 Correct 71 ms 344 KB Output is correct
27 Correct 605 ms 344 KB Output is correct
28 Correct 716 ms 452 KB Output is correct
29 Correct 707 ms 344 KB Output is correct
30 Correct 2331 ms 452 KB Output is correct
31 Correct 360 ms 344 KB Output is correct
32 Correct 6 ms 600 KB Output is correct
33 Correct 6 ms 600 KB Output is correct
34 Correct 5 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
36 Execution timed out 4067 ms 1880 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4062 ms 2648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4072 ms 856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Correct 25 ms 340 KB Output is correct
4 Correct 577 ms 448 KB Output is correct
5 Correct 123 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 30 ms 452 KB Output is correct
8 Correct 6 ms 600 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 5 ms 476 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 5 ms 600 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 105 ms 452 KB Output is correct
17 Correct 9 ms 344 KB Output is correct
18 Correct 6 ms 600 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 101 ms 468 KB Output is correct
21 Correct 389 ms 344 KB Output is correct
22 Correct 168 ms 344 KB Output is correct
23 Correct 6 ms 600 KB Output is correct
24 Correct 5 ms 600 KB Output is correct
25 Correct 52 ms 344 KB Output is correct
26 Correct 71 ms 344 KB Output is correct
27 Correct 605 ms 344 KB Output is correct
28 Correct 716 ms 452 KB Output is correct
29 Correct 707 ms 344 KB Output is correct
30 Correct 2331 ms 452 KB Output is correct
31 Correct 360 ms 344 KB Output is correct
32 Correct 6 ms 600 KB Output is correct
33 Correct 6 ms 600 KB Output is correct
34 Correct 5 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
36 Execution timed out 4067 ms 1880 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4003 ms 6932 KB Time limit exceeded
2 Halted 0 ms 0 KB -