#P6704. [COCI 2010/2011 #7] GITARA
[COCI 2010/2011 #7] GITARA
Description
You have a matrix , and initially all entries are .
For each required position , you must satisfy:
-
At that moment, is .
-
For where , the value is .
You need to find the minimum number of state changes while satisfying all requirements.
Input Format
The first line contains two positive integers , which represent the number of notes in the melody and the number of frets on each string.
The next lines each contain two positive integers , representing the position (string number and fret number) that can produce the corresponding note, in the order played by the alien.
Output Format
Output one non-negative integer: the minimum number of finger movements made by the alien.
5 15
2 8
2 10
2 12
2 10
2 5
7
7 15
1 5
2 3
2 5
2 7
2 4
1 5
1 3
9
Hint
Explanation for Sample 1
All notes are produced on the second string. First press frets in order (). Then release fret (). Finally, press fret and release frets ().
Explanation for Sample 2
For each operation, the required numbers of finger movements are .
Constraints
Pressing or releasing a fret counts as one finger movement. Plucking the string does not count as a finger movement; it is a guitar-playing action (meaning you do not need to care how it is plucked, only the pressing is considered. Maybe the alien can use superpowers.)
For of the testdata, , .
Notes
This problem is worth points in total.
Translated from COCI2010-2011 CONTEST #7 T3 GITARA.
Translated by ChatGPT 5
京公网安备 11011102002149号