#P2614. 计算器弹琴
计算器弹琴
Description
In a certain mode of the calculator, pressing a key, for example 1, will produce the middle pitch Do.
Here is the key-to-pitch table.
+ 低音Fa
< 低音So
* 低音La
/ 低音Xi
1 中音Do
2 中音Re
3 中音Mi
4 中音Fa
5 中音So
6 中音La
7 高音Xi
8 高音Do
9 高音Re
= 高音Mi
% 高音Fa
C 高音So
M 高音La
Now Xiao A has obtained a piece of sheet music — we call it calculator notation, a variant of numbered musical notation (jianpu).
Durations (i.e., how long you press) are recorded as follows, for example:
1 is a quarter note, taking beat.
1- is a half note, taking beats.
1--- is a whole note, taking beats.
For notes shorter than a quarter note, we use nested parentheses, for example:
(1(34(56))2)
1 and 2 are inside one layer of parentheses, so they are eighth notes, taking beat.
3 and 4 are inside two layers of parentheses, so they are sixteenth notes, taking beat.
5 and 6 are inside three layers of parentheses, so they are thirty-second notes, taking beat.
At most thirty-second notes will appear in the testdata; there are no shorter notes.
The symbol - will not appear inside parentheses.
Adding a dot . after a note means the note is extended by of its original duration.
For example, 1-. is beats, 1. is beats, and in (3.(45.)), 3 is beat, 4 is beat, and 5 is beat.
There will not be two or more consecutive dots. A whole note will not be dotted.
Ignore other musical symbols.
In addition, the entire score provides an integer , the number of beats per minute.
For readability, the score may contain arbitrary line breaks and spaces. They can be ignored when reading the input.
Now Xiao A wants to know how many seconds it takes to finish playing this score.
Input Format
The first line contains two integers , the number of lines of the score and the beats per minute.
The next lines contain the score.
Output Format
Output a single integer: the total time in seconds needed to perform the score. If the exact time is fractional, round down to an integer.
2 60
3345 5432 1123 322-
3345 5432 1123 211-
32
5 120
3(1.(3))55 8(7.(6))65 655(3.(1)) (4.(4))32-
3(1.(2))35 8(7.(6))65 655(4.(3)) (2.(3))21-
2.(3)44 6(6.(6))(5.(4))3 3.(5)88 (9.(8)7.(6))5-
=.(=)(9.(8))7 9.(8)(7.(6))5 8(856543) (2.(3))43-
=.(=)(9.(8))7 9.(8)(7.(6))5 8(857654) (3.(4))21-
40
Hint
- Sample Explanation
For the first sample, there are quarter notes and half notes, totaling beats. With beats per minute, the total time is seconds.
- Constraints
For of the testdata, the characters (, ), and . do not appear.
For of the testdata, , and each line contains at most characters.
Translated by ChatGPT 5
京公网安备 11011102002149号