Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- int a[100000] = {};
- for (int i = 0; i < n; ++i) cin >> a[i];
- int c = 0;
- int last = 0;
- for (int i = 0; i < n; ++i) {
- int v = a[i];
- int next = -1;
- if (i+1<n) next = a[i+1];
- // cout << "i:" << i << " last:" << last << " v:" << v << " next:" << next << endl;
- if (v == 0) {
- last = 0;
- } else if (v == 3) {
- if (next == 1) {
- last = 2;
- c++;
- } else {
- last = 1;
- c++;
- }
- } else { //1, 2
- if (last == v) {
- last = 0;
- } else { //v != last
- // if (next == 0 || next == v || next == 3) {
- // last = v;
- // c++;
- // } else {
- //last = 0;
- last = v;
- c++;
- }
- }
- }
- }
- cout << c << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement