Baltic Olympiad in Informatics: 2015 Day 1, Problem 1
Byteasar is a fan of both bowling and statistics. He has written down the results of a few past bowling games. Unfortunately, some characters in the notes are blurry, and thus unreadable. Byteasar asks you to write a program to calculate the number of distinct games which are consistent with his notes.
A bowling game consists of
For each shot the player receives as basic points the total number of pins knocked down in this shot. The
player's basic points in each frame are the sum of basic points of all the shots in this frame. If all
For a simple frame the rules are the following:
If a player knocks down all
pins in the first shot of a frame, she gets a strike and the frame ends. As bonus points she gets the sum of basic points of her next two shots. A strike is denoted asx-
.If a player knocks down all
pins using both shots of a frame, she gets a spare. As bonus points she gets the basic points of her next shot. A spare is denoted asA/
, where is a digit describing the number of pins knocked down in the first shot of the frame.If
or fewer pins are knocked down after both shots, the player gets just basic points and such a frame is denoted asAB
, where is the one-digit number of pins knocked down in the first shot, and is the one-digit number of pins knocked down in the second shot .
Note that bonus points are included to the score of a frame in which the strike or the spare was obtained, regardless of the fact that the exact number of bonus points depends on future shots in next frames.
For the final frame the rules are the following:
Initially the player receives two shots in this frame. If
or fewer pins are knocked down in the two shots, the frame ends. Otherwise (if the first two shots are a spare or the first shot is a strike), the player receives a third shot in the frame. Whenever the player knocks down all the pins in any of the three shots, the pins are reset to the initial configuration for the next shot. The score of the final frame is the total number of pins knocked down (note that no bonus points are earned due to strikes and spares).Overall there are seven possible configurations of the final frame with the following outcomes (
and stand for one-digit numbers):
Denotation | Description | Frame Score |
---|---|---|
xxx | Three consecutive strikes | |
xxA | Two consecutive strikes and a shot with | |
xA/ | A strike and a spare with | |
xAB | A strike and two following shots with | |
A/x | A spare with | |
A/B | A spare with | |
AB- | Two shots with |
Each game is described as a sequence of 08x-7/2/x-x-23441/0/x
, the player's points after respective frames were as follows:
Frame | Denotation | Basic Points | Bonus Points | Frame Score | Total |
---|---|---|---|---|---|
08 | |||||
x- | |||||
7/ | |||||
2/ | |||||
x- | |||||
x- | |||||
23 | |||||
44 | |||||
1/ | |||||
Final | 0/x |
Input Specification
The first line of input contains one integer
The first line of a test case description contains one integer ?
characters. The third line contains -1
.
Output Specification
Your program should output
For each test case your program should write one integer: the number of possible distinct games corresponding to the test case. Two games are considered different if and only if they differ in at least one shot,
that is, their
Constraints
Subtask | Conditions (in each test case) | Points |
---|---|---|
1 | At most six ? characters in the input sequence. | |
2 | The result is at most | |
3 | No game whose description contains any characters x or / is consistent with the input data. | |
4 | The input sequence ends with 00- (that is, the player obtained -1 . | |
5 | No additional constraints. |
Sample Input
2
10
08x-7/2/x?x-23??1/???
8 -1 40 60 82 97 102 110 120 140
5
x-x-23?/00-
22 37 42 52 52
Sample Output
9
10
Explanation for Sample
In the first case, in frame x
, the only possible character
is -
. In frame
In the second case, any character from
Additional Sample Test
In the data we provide you with an additional sample test with multiple test cases with
Comments
Since the time limit was too loose, it was scaled, and all submissions were rejudged.