Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include<iostream>
- #include<string>
- #include<conio.h>
- #include<vector>
- #include<algorithm>
- using namespace std;
- int main() {
- // freopen("out.txt", "wt", stdout); freopen("in.txt", "rt", stdin);
- vector<vector<int>> a;
- a.resize(3);
- bool contest = true;
- bool sport = true;
- int n;
- int g;
- cin >> n;
- cin >> g;
- a[0].push_back(0);
- if (g == 0) {
- a[1].push_back(0);
- a[2].push_back(0);
- }
- if (g == 1) {
- a[1].push_back(1);
- a[2].push_back(0);
- contest = false;
- }
- if (g == 2) {
- a[1].push_back(0);
- a[2].push_back(1);
- sport = false;
- }
- if (g == 3) {
- a[1].push_back(1);
- a[2].push_back(1);
- contest = false;
- sport = false;
- }
- for (int i = 1; i < n; i++) {
- cin >> g;
- if (g == 0) {
- a[0].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- contest = true;
- sport = true;
- }
- if (g == 1) {
- a[0].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- if (contest == true) {
- a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1]))+1);
- contest = false;
- }
- else {
- a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- contest = true;
- }
- a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- sport = true;
- }
- if (g == 2) {
- a[0].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- if (sport == true) {
- a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])) + 1);
- sport = false;
- }
- else {
- a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- sport = true;
- }
- contest = true;
- }
- if (g == 3) {
- a[0].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- if (contest == true) {
- a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])) + 1);
- contest = false;
- }
- else {
- a[1].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- contest = true;
- }
- if (sport == true) {
- a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])) + 1);
- sport = false;
- }
- else {
- a[2].push_back(max(a[0][i - 1], max(a[1][i - 1], a[2][i - 1])));
- sport = true;
- }
- }
- }
- int k = (n - max(a[0][n - 1], max(a[1][n - 1], a[2][n - 1])));
- cout << k;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement