제출 #968052

#제출 시각아이디문제언어결과실행 시간메모리
968052willychanLine Town (CCO23_day1problem3)C++17
0 / 25
1 ms348 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...