This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
#define ll long long
#define pii pair<int,int>
#define fs first
#define sc second
const int mxn = 5e5+10;
int N;
int arr[mxn];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N;
for(int i = 1;i<=N;i++)cin>>arr[i];
int cnt[2] = {};
for(int i = 1;i<=N;i++){
if(arr[i]<0)cnt[i&1]++;
}
if(cnt[1]-cnt[0] != 1&&cnt[1]-cnt[0] != 0){
cout<<"-1\n";
return 0;
}
int lp = N,rp = 0;
for(int i = 1;i<=N;i++){
if(arr[i]<0)rp = max(rp,i);
else lp = min(lp,i);
}
cout<<max(0,rp-lp);
}
# | 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... |