Mock CCC '20 Contest 1 J4 - A Binary Problem

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 1.0s
Memory limit: 1G

Problem type

koosaga lives on a street with N houses, all equally spaced apart. Each house either has the lights on or off. koosaga rates a house with a score equal to the minimum distance, in house units, that he must travel to be at a house that has its lights on.

koosaga wants to compute the sum of the ratings of all the houses on his street.

Constraints

1 \le N \le 10^6

In tests worth 5 marks, N \le 10^3.

At least one house will always have its lights on.

Input Specification

The first line contains a single positive integer, N.

The next line contains a binary string. If the ith character of the string is 1, then the ith house has its lights on. Otherwise, the ith character of the string is 0 and that house has its lights off.

Output Specification

Output the sum of all the ratings.

Sample Input 1

3
111

Sample Output 1

0

Explanation for Sample 1

Every house is illuminated, so every house has a rating of 0.

Sample Input 2

4
1001

Sample Output 2

2

Explanation for Sample 2

The first and last house have ratings of 0, and the second and third house each have a rating of 1.


Comments


  • 0
    Rui77989  commented on Dec. 14, 2023, 1:26 a.m.

    Help me! check my code pls


  • 0
    Ze  commented on March 24, 2022, 8:38 p.m.

    Can someone check my code and see why my algorithm isn't working for test case 12? It worked for all of the test cases I've tried myself.


  • 0
    Krish120003  commented on Feb. 3, 2021, 9:53 p.m. edited

    I'm getting case 12 wrong, but I'm not sure what the issue with my algorithm is. Can someone please advise?


    • -3
      Brian_Li23  commented on Feb. 18, 2021, 5:25 p.m. edited

      You most likely misunderstood the question, reread the question.


  • 0
    ItzMidnightShadowWolf  commented on Aug. 14, 2020, 2:20 p.m. edit 2

    Can someone tell me what to do..?

    Please?

    #Confusion


    • 7
      boolean  commented on Aug. 14, 2020, 3:10 p.m. edit 2

      As for all problems, read the problem carefully and try and construct a solution. If you're stuck, there's an editorial explaining this question that you can access right above "Points:5 (partial)".

      For future reference, it usually isn't wise to ask for help on a question in the comments without trying to code it first. Asking for help with specific parts of the problem or parts of your code is fine, but don't ask the comments how to do an entire question. If you need to ask someone this type of question, the DMOJ discord is a better place to do it. Hope this helps!