Skip to content

Instantly share code, notes, and snippets.

@estelabn
Created May 7, 2023 23:50
Show Gist options
  • Save estelabn/7ea08bb7e468f0a144323cb0932e80c4 to your computer and use it in GitHub Desktop.
Save estelabn/7ea08bb7e468f0a144323cb0932e80c4 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
int main(){
int c; cin >> c;
vector<int> v(c+5,0), res(c+5, -1);
for(int i=1; i<=c; i++) cin >> v[i];
res[1] = 0;
for(int i=1; i<c; i++){
if(v[i] == 0) continue;
if(res[i] == -1) continue;
if(v[i+1] == 1 and res[i+1] == -1) res[i+1] = res[i] + 1;
if(v[i+2] == 1 and res[i+2] == -1) res[i+2] = res[i] + 1;
}
cout << res[c] << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment