이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++) cin>>a[i];
int prev = 0;
vector<pair<int,int> > arr;
for(int i=1;i<n;i++){
if(a[i]!=a[i-1]){
arr.push_back({i-prev,a[prev]});
prev = i;
}
}
arr.push_back({n-prev,a[prev]});
int N = arr.size();
int l = 0;
int r = N;
int cnt = 0;
for(int i=N-1;i>=0;i--){
if(arr[i].second==-1 && arr[i].first%2) {
l = i+1;
break;
}
}
for(int i=0;i<N;i++){
if(arr[i].second==1 && arr[i].first%2) {
r = i;
break;
}
}
for(int i=0;i<N;i++) if(arr[i].second==-1) cnt+=arr[i].first/2;
int minn = 1e9;
if(l>r){
cout<<-1<<"\n";
return 0;
}
for(int i=0;i<l;i++){
if(arr[i].second==-1) cnt-=arr[i].first/2;
else cnt+=arr[i].first/2;
}
minn = cnt;
for(int i=l;i<r;i++){
if(arr[i].second==-1) cnt-=arr[i].first/2;
else cnt+=arr[i].first/2;
minn = min(cnt,minn);
}
cout<<minn<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |