codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

698A.md (2784B)


      1 Source: https://codeforces.com/problemset/problem/698/A
      2 
      3 A. Vacations
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
     22 
     23 1. on this day the gym is closed and the contest is not carried out;
     24 2. on this day the gym is closed and the contest is carried out;
     25 3. on this day the gym is open and the contest is not carried out;
     26 4. on this day the gym is open and the contest is carried out.
     27 
     28 On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
     29 
     30 Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
     31 
     32 Input
     33 
     34 The first line contains a positive integer *n* (1 ≤ *n* ≤ 100) — the number of days of Vasya's vacations.
     35 
     36 The second line contains the sequence of integers *a*1, *a*2, ..., *a**n* (0 ≤ *a**i* ≤ 3) separated by space, where:
     37 
     38 * *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out;
     39 * *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out;
     40 * *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out;
     41 * *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
     42 
     43 Output
     44 
     45 Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
     46 
     47 * to do sport on any two consecutive days,
     48 * to write the contest on any two consecutive days.
     49 
     50 Examples
     51 
     52 Input
     53 
     54 ```
     55 4  
     56 1 3 2 0
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 2
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 7  
     69 1 3 3 2 1 2 3
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 0
     76 ```
     77 
     78 Input
     79 
     80 ```
     81 2  
     82 2 2
     83 ```
     84 
     85 Output
     86 
     87 ```
     88 1
     89 ```
     90 
     91 Note
     92 
     93 In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
     94 
     95 In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
     96 
     97 In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.