Submission #836957

# Submission time Handle Problem Language Result Execution time Memory
836957 2023-08-24T18:12:41 Z Abrar_Al_Samit Radio Towers (IOI22_towers) C++17
17 / 100
782 ms 5616 KB
#include "towers.h"
#include <bits/stdc++.h>
 
using namespace std;
 
//subtask 2 & 3
 
const int nax = 100005;
int n;
bool l_maxima[nax];
int l[nax], r[nax];
int pmax[nax], nmax[nax];
bool is[nax];
vector<int>pl;
 
void init(int N, vector<int> H) {
 	n = N;
	int mn = H[0];
	for(int i=1; i<n-1; ++i) {
		if(H[i]>H[i-1] && H[i]>H[i+1]) {
			l_maxima[i] = 1;
			l[i] = H[i] - mn;
			mn = 2e9;
		} else {
			mn = min(mn, H[i]);
		}
	}


	int p = -1;
	for(int i=1; i<n; ++i) if(l_maxima[i]) {
		pmax[i] = p;
		p = i;
	}
	p = n;
	for(int i=n-1; i>0; --i) if(l_maxima[i]) {
		nmax[i] = p;
		p = i;
	}

	mn = H[n-1];
	for(int i=n-2; i>0; --i) {
		if(l_maxima[i]) {
			r[i] = H[i] - mn;
			mn = 2e9;
		} else {
			mn = min(mn, H[i]);
		}
	}


	set<pair<int,int>>s;
	for(int i=1; i<n; ++i) if(l_maxima[i]) {
		s.insert(make_pair(min(l[i], r[i]), i));
		is[i] = 1;
	}
	while(!s.empty()) {
		auto [x, i] = *s.begin();
		s.erase(s.begin());
		is[i] = 0;

		pl.push_back(min(l[i], r[i]));
 
		int lmin = H[i] - l[i], rmin = H[i] - r[i];
 
		if(pmax[i]!=-1 && is[pmax[i]]) {
			s.erase(make_pair(min(l[pmax[i]], r[pmax[i]]), pmax[i]));
			r[pmax[i]] = max(r[pmax[i]], H[pmax[i]] - rmin);
			s.insert(make_pair(min(l[pmax[i]], r[pmax[i]]), pmax[i]));

			nmax[pmax[i]] = nmax[i];
		}
		if(nmax[i]!=n && is[nmax[i]]) {
			s.erase(make_pair(min(l[nmax[i]], r[nmax[i]]), nmax[i]));
			l[nmax[i]] = max(l[nmax[i]], H[nmax[i]] - lmin);
			s.insert(make_pair(min(l[nmax[i]], r[nmax[i]]), nmax[i]));

			pmax[nmax[i]] = pmax[i];
		}
	} 
}
 
int max_towers(int L, int R, int D) {
	int ans =  pl.end() - lower_bound(pl.begin(), pl.end(), D);
	++ans;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 316 ms 720 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 506 ms 4768 KB 1st lines differ - on the 1st token, expected: '11903', found: '33010'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 229 ms 1352 KB Output is correct
2 Correct 648 ms 4724 KB Output is correct
3 Correct 782 ms 4680 KB Output is correct
4 Correct 677 ms 5448 KB Output is correct
5 Correct 698 ms 5448 KB Output is correct
6 Correct 633 ms 5448 KB Output is correct
7 Correct 599 ms 5528 KB Output is correct
8 Correct 494 ms 976 KB Output is correct
9 Correct 576 ms 976 KB Output is correct
10 Correct 742 ms 1104 KB Output is correct
11 Correct 775 ms 1104 KB Output is correct
12 Correct 42 ms 4680 KB Output is correct
13 Correct 57 ms 5576 KB Output is correct
14 Correct 64 ms 5568 KB Output is correct
15 Correct 12 ms 976 KB Output is correct
16 Correct 9 ms 1104 KB Output is correct
17 Correct 42 ms 4516 KB Output is correct
18 Correct 43 ms 4776 KB Output is correct
19 Correct 49 ms 4784 KB Output is correct
20 Correct 58 ms 5448 KB Output is correct
21 Correct 62 ms 5448 KB Output is correct
22 Correct 69 ms 5616 KB Output is correct
23 Correct 59 ms 5548 KB Output is correct
24 Correct 11 ms 1088 KB Output is correct
25 Correct 9 ms 976 KB Output is correct
26 Correct 10 ms 1104 KB Output is correct
27 Correct 9 ms 1104 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 388 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 304 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 208 KB Output is correct
41 Correct 0 ms 208 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 316 ms 720 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -