CCC '11 S5 - Switch

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 2.0s
Memory limit: 64M

Problem type

Canadian Computing Competition: 2011 Stage 1, Senior #5

You are walking by a row of K (4 \le K \le 25) lights, some of which are on and some of which are off. In this initial configuration, there is no consecutive sequence of four lights that are on.

Whenever four or more consecutive lights are on, the lights in that consecutive block will turn off. You can only turn on lights that are off.

What is the minimum number of lights you need to turn on in order to end up with all K lights off?

Input Description

The first line of input will consist of the integer K, indicating the number of lights. Each of the next K lines will have either the integer 0 (to represent a light that is off) or the integer 1 (to represent a light that is on).

Output Specification

Your program should output the minimum number of lights that must be turned on in order to have all K lights be off.

Sample Input 1

5
1
1
0
1
1

Output for Sample Input 1

1

Explanation of Sample 1

Notice that turning on the third light will create five consecutive lights that are on, which will in turn cause all of these five lights to be off.

Note: At least 30% of the test cases will have K \le 10.


Comments


  • 0
    Roronoa_Zoro1540  commented on Oct. 13, 2018, 7:33 p.m.

    I don't know why i keep getting RTE for the last case? Could someone send help pls


  • 0
    Dordor1218  commented on May 20, 2018, 10:20 a.m.

    It says "You are walking by a row" so do you need to do it from right to left or can it be random


    • 3
      liwi  commented on May 20, 2018, 2:19 p.m.

      It can be random.


  • 13
    root  commented on Jan. 30, 2017, 4:33 p.m.
    Computer Science

    "You can only turn on lights that are off." - I certainly hope so.


  • 1
    bobhob314  commented on Dec. 26, 2015, 5:30 p.m. edited
    RTE

    Hey guys, not sure why I'm getting RTE on DMOJ but not locally. Any ideas?


    • 0
      XIAOAGE  commented on Dec. 26, 2015, 5:48 p.m.

      the integer array is too huge. It takes up more than 64M


      • -1
        bobhob314  commented on Dec. 26, 2015, 5:54 p.m.

        Thanks bud.