Submission #968254

#TimeUsernameProblemLanguageResultExecution timeMemory
968254LittleOrangeLine Town (CCO23_day1problem3)C++17
0 / 25
0 ms348 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const ll big = 1e18; int main(){ ios::sync_with_stdio(0);cin.tie(0); ll n; cin >> n; vector<ll> a(n); for(ll &i : a) cin >> i; vector<ll> l(n,big),r(n,big); ll cur = 0; vector<ll> b = a; for(ll i = 0;i<n;i++){ if (b[i]==1){ if (i+1==n) break; if (b[i+1]==1){ b[i] = -1; b[i+1] = -1; cur++; }else{ if (i+2==n||b[i+2]!=-1) break; b[i] = -1; b[i+2] = 1; } } l[i] = cur; } b = a; reverse(b.begin(),b.end()); cur = 0; for(ll i = 0;i<n;i++){ if (b[i]==-1){ if (i+1==n) break; if (b[i+1]==-1){ b[i] = 1; b[i+1] = 1; cur++; }else{ if (i+2==n||b[i+2]!=1) break; b[i] = 1; b[i+2] = -1; } } r[i] = cur; } ll ans = min(l.back(),r.back()); for(ll i = 0;i<n-1;i++){ ans = min(ans,l[i]+r[n-2-i]); } cout << (ans>=big?-1:ans) << "\n"; }
#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...