#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
#define z exit(0)
#define mp make_pair
#define F first
#define S second
using namespace std;
using pii = pair<int,int>;
const int inf = 1e9;
int cp[1000000], m;
set<pii> s;
vector<int> to_remove[1000000];
int gw(int n, int H[]){
for(int i = m = 0; i<n; ++i) if(H[i]) cp[m++] = H[i];
for(int i = 0; i<m; ++i) to_remove[i].clear();
sort(cp, cp+m); m = unique(cp, cp+m) - cp;
for(int i = 0; i<n; ++i) if(H[i]) to_remove[lower_bound(cp, cp+m, H[i]) - cp].push_back(i);
for(int i = 0, j = 0; i<n; ){
for(; j<n && H[j+1] > 0; ++j){}
s.emplace(i, j);
i = j+2; j = i;
}
int mx = (int)s.size();
for(int t = 0; t<m; ++t){
for(int j : to_remove[t]){
set<pii>::iterator itr = (--s.upper_bound(mp(j, inf)));
if(itr == s.end()) continue;
int l = itr->F, r = itr->S;
s.erase(itr);
if(l <= j-1) s.emplace(l, j-1);
if(j+1 <= r) s.emplace(j+1, r);
}
mx = max(mx, (int)s.size());
}
return mx;
}
signed main(){
int n; scanf("%d", &n);
int H[n];
for(int i = 0; i<n; ++i) scanf("%d", H+i);
printf("%d", gw(n, H));
}
Compilation message
gw.cpp: In function 'int main()':
gw.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
gw.cpp:43:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | for(int i = 0; i<n; ++i) scanf("%d", H+i);
| ~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
8 ms |
23900 KB |
Output is correct |
3 |
Correct |
9 ms |
23900 KB |
Output is correct |
4 |
Correct |
10 ms |
24048 KB |
Output is correct |
5 |
Incorrect |
9 ms |
23896 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
26448 KB |
Output is correct |
2 |
Correct |
37 ms |
26448 KB |
Output is correct |
3 |
Correct |
42 ms |
26624 KB |
Output is correct |
4 |
Correct |
34 ms |
26440 KB |
Output is correct |
5 |
Incorrect |
35 ms |
26616 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
29524 KB |
Output is correct |
2 |
Correct |
41 ms |
30544 KB |
Output is correct |
3 |
Correct |
64 ms |
29632 KB |
Output is correct |
4 |
Correct |
73 ms |
29568 KB |
Output is correct |
5 |
Correct |
67 ms |
29520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
475 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
980 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |