#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
struct pi{
int h,x,y;
};
bool operator<(const pi &a, const pi &b){
return a.h>b.h;
}
priority_queue<pi> pq;
set<int> st;
map<int,int> re;
void init(int N, std::vector<int> H) {
bool ch = false;
if(N==1) st.insert(0);
for(int i=1;i<N;i++){
if(!ch&&H[i-1]<H[i]){
st.insert(i-1);
ch = true;
}
else if(ch&&H[i-1]>H[i]){
st.insert(i-1);
ch = false;
}
}
if(!ch) st.insert(N-1);
//for(auto x:st) printf("%d\n",x);
auto it = st.begin(), nit = it;
nit++;
while(nit!=st.end()){
pq.push({abs(H[*nit]-H[*it]),*it,*nit});
it++; nit++;
}
int d=0;
while(!pq.empty()){
int h=pq.top().h,x=pq.top().x,y=pq.top().y; pq.pop();
if(!st.count(x)||!st.count(y)) continue;
//printf("%d %d %d %d\n",h,x,y,(int)st.size());
if(h!=d){
re[d+1]=((int)st.size()-1)/2+1;
//printf("%d %d\n",d,re[d+1]);
d=h;
}
st.erase(x); st.erase(y);
it=st.lower_bound(x); nit=st.upper_bound(y);
if(it!=st.begin()&&nit!=st.end()){
it--;
pq.push({abs(H[*nit]-H[*it]),*it,*nit});
}
}
re[d+1]=1;
}
int max_towers(int L, int R, int D) {
auto it = re.upper_bound(D);
it--;
return it->second;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
500 ms |
680 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 |
208 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 |
208 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 |
777 ms |
5796 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 |
285 ms |
1560 KB |
Output is correct |
2 |
Correct |
888 ms |
5788 KB |
Output is correct |
3 |
Correct |
763 ms |
5788 KB |
Output is correct |
4 |
Correct |
1040 ms |
7436 KB |
Output is correct |
5 |
Correct |
1205 ms |
7316 KB |
Output is correct |
6 |
Correct |
976 ms |
7344 KB |
Output is correct |
7 |
Correct |
1130 ms |
7308 KB |
Output is correct |
8 |
Correct |
1014 ms |
1048 KB |
Output is correct |
9 |
Correct |
873 ms |
968 KB |
Output is correct |
10 |
Correct |
886 ms |
1060 KB |
Output is correct |
11 |
Correct |
701 ms |
1052 KB |
Output is correct |
12 |
Correct |
96 ms |
5828 KB |
Output is correct |
13 |
Correct |
141 ms |
7436 KB |
Output is correct |
14 |
Correct |
148 ms |
7320 KB |
Output is correct |
15 |
Correct |
11 ms |
1048 KB |
Output is correct |
16 |
Correct |
10 ms |
1056 KB |
Output is correct |
17 |
Correct |
83 ms |
4956 KB |
Output is correct |
18 |
Correct |
89 ms |
5824 KB |
Output is correct |
19 |
Correct |
97 ms |
5788 KB |
Output is correct |
20 |
Correct |
147 ms |
7344 KB |
Output is correct |
21 |
Correct |
149 ms |
7312 KB |
Output is correct |
22 |
Correct |
144 ms |
7376 KB |
Output is correct |
23 |
Correct |
145 ms |
7356 KB |
Output is correct |
24 |
Correct |
14 ms |
1064 KB |
Output is correct |
25 |
Correct |
17 ms |
1052 KB |
Output is correct |
26 |
Correct |
12 ms |
1056 KB |
Output is correct |
27 |
Correct |
11 ms |
1052 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
2 ms |
448 KB |
Output is correct |
31 |
Correct |
1 ms |
292 KB |
Output is correct |
32 |
Correct |
1 ms |
208 KB |
Output is correct |
33 |
Correct |
1 ms |
356 KB |
Output is correct |
34 |
Correct |
1 ms |
292 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
2 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
336 KB |
Output is correct |
38 |
Correct |
2 ms |
336 KB |
Output is correct |
39 |
Correct |
2 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
208 KB |
Output is correct |
41 |
Correct |
1 ms |
208 KB |
Output is correct |
42 |
Correct |
1 ms |
208 KB |
Output is correct |
43 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 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 |
500 ms |
680 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |