#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef pair<int,int>ii;
int N,a[1000000],ch=0,ans=-1;
vector<ii>b;
//0=land,1=no land
bool f[1000000]={};
int main(){
cin>>N;
for(int i=0;i<N;++i){
cin>>a[i];
b.push_back({a[i],i});
}
sort(b.begin(),b.end());
if(b[0].first>0)ans=1;
for(int i=0;i<N;++i){
int x=b[i].second;
if(x!=0)ch+=(f[x]==f[x-1]?1:-1);
if(x!=N-1)ch+=(f[x]==f[x+1]?1:-1);
f[x]=1;
if((i==N-1)||(b[i].first!=b[i+1].first)){
int isl;
if(f[0]){
//011223344...
isl=ch/2+ch%2;
}else{
//112233445...
isl=ch/2+1;
}
ans=max(ans,isl);
}
}
// deallocate memory of vector (workaround for memory bug?)
vector<ii>().swap(b);
cout<<ans<<'\n';return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
3 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
2040 KB |
Output is correct |
2 |
Correct |
36 ms |
2040 KB |
Output is correct |
3 |
Correct |
36 ms |
2076 KB |
Output is correct |
4 |
Correct |
38 ms |
2076 KB |
Output is correct |
5 |
Correct |
37 ms |
2076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
2076 KB |
Output is correct |
2 |
Correct |
44 ms |
2076 KB |
Output is correct |
3 |
Correct |
55 ms |
2076 KB |
Output is correct |
4 |
Correct |
56 ms |
2076 KB |
Output is correct |
5 |
Correct |
53 ms |
2076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
606 ms |
13348 KB |
Output is correct |
2 |
Correct |
591 ms |
13464 KB |
Output is correct |
3 |
Correct |
599 ms |
13496 KB |
Output is correct |
4 |
Correct |
604 ms |
13496 KB |
Output is correct |
5 |
Correct |
599 ms |
13496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
605 ms |
13496 KB |
Output is correct |
2 |
Correct |
616 ms |
13540 KB |
Output is correct |
3 |
Correct |
596 ms |
13540 KB |
Output is correct |
4 |
Correct |
370 ms |
13540 KB |
Output is correct |
5 |
Correct |
381 ms |
16212 KB |
Output is correct |