Back
Close

The Implicit Restroom Laws of Politness

Statement

 Goal

Out of politness (privacy, splashes, social distancing), men will choose specific urinals in public restrooms. Men:
- never choose a urinal adjacent to another men;
- choose the furtest urinal from anyother men; and
- choose urinals closest the exit (leftmost urinals).

Given a urinal situation where 0 represents an empty urinal and T represents the amount of time left for men to relieve himself. How much S seconds will it take for all men to relieve themselves.

Men relieve themselves in exactly 8 seconds.
Men walk to empty urinals in 1 seconds, one after the other.
Input
Line 1: situation a string representing urinals
Line 2: Q an integer for mens waiting in line
Output
S seconds
Constraints
0 < Q < 20
1 < T < 9
0 < situation length < 20
8 < S < 171
Example
Input
0000605
3
Output
14 seconds

Game modes
Fastest, Shortest

Test cases
Plenty of room for everyone Test
Input
0000605 3
Output
14 seconds

Validator 1 Validator
Input
0000607 3
Output
15 seconds

Busy room, someone will have to wait Test
Input
0000000 2
Output
10 seconds

Validator 2 Validator
Input
0000030 2
Output
10 seconds

Small room Test
Input
0 4
Output
36 seconds

Validator 3 Validator
Input
0 5
Output
45 seconds

Call dispatch! Test
Input
00200408000306004040 11
Output
19 seconds

Validator 4 Validator
Input
00300509000407005050 11
Output
20 seconds

Dry day Test
Input
00000000000000030 0
Output
3 seconds

Validator 5 Validator
Input
00000000000004070 0
Output
7 seconds

Solution language

Solution

Stub generator input