Knob
Time limit0.5sMemory limit1024 MB
Given left and right knob directions for T beats, sum a point for each knob repeating its previous direction and a point for both knobs turning the same way on one beat.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Knob
A voice actor has been hooked on a rhythm game that requires operating two knobs precisely on the beat. The knob system works as follows.
- There are two knobs, a left knob and a right knob.
- Each knob can be turned clockwise or counterclockwise. A knob can also be left still.
The song has length . On the -th beat (), the left knob is operated according to , and the right knob is operated according to , as follows.
- If the value is , the knob stays still.
- If the value is , the knob is turned counterclockwise. If the value is , the knob is turned clockwise.
The fun score of the song is the sum of the values measured on every beat by these rules.
- On the 2nd beat or later, if the left knob turns in the same direction as on the previous beat, the fun score increases by .
- On the 2nd beat or later, if the right knob turns in the same direction as on the previous beat, the fun score increases by .
- If both knobs turn on the same beat and turn in the same direction, the fun score increases by an additional .
Compute the fun score for the voice actor.
Input
The first line contains an integer , the length of the song. ()
From the 2nd line to the -th line, the -th line contains two integers and separated by a space, which describe how to operate the knobs on the -th beat. Each number is one of , , or .
Output
Print the fun score of the song on the first line.
Hint
Slow input and output can cause time limit errors when reading or printing many lines. The following methods are recommended for each language.
-
C++: To use
cin/cout, add the following two lines at the start ofmainand use\ninstead ofendlwhen reading input. After this, C input and output functions such asscanf,printf,puts,getchar, andputcharmust not be used.cin.tie(nullptr);sync_with_stdio(false);
-
Python: Instead of
input, usesys.stdin.readline.rstrip(). -
Java and Kotlin: Use
BufferedReaderandBufferedWriterinstead ofScannerandSystem.out.println. CallBufferedWriter.flushonce before the program ends.