#P2743. [USACO5.1] 乐曲主题Musical Themes
[USACO5.1] 乐曲主题Musical Themes
Description
We represent a piece of music by a sequence of () notes, each an integer in the range , where each number denotes a key on the piano. Unfortunately, this way of encoding a melody ignores note durations, but this programming task concerns pitch only and is independent of duration.
Many composers build a piece around a recurring "theme". In our representation, a "theme" is a substring of the entire note sequence that satisfies the following conditions:
- Its length is at least notes.
- It appears repeatedly in the piece (possibly after transposition, see below).
- The repeated occurrences of the same theme must be non-overlapping.
"Transposition" means that each note in the theme sequence is increased or decreased by the same integer. Given a piece, compute the length (number of notes) of the longest theme.
The time limit for this problem is second.
Input Format
The first line of input contains the integer .
Each of the following lines (except possibly the last) contains integers representing the note sequence.
The last line may contain fewer than notes.
Output Format
Output a single integer, the length of the longest theme. If there is no theme, output 0.
30
25 27 30 34 39 45 52 60 69 79 69 60 52 45 39 34 30 26 22 18
82 78 74 70 66 67 64 60 65 80
5
Hint
The statement is translated from NOCOW.
USACO Training Section 5.1.
Translated by ChatGPT 5
京公网安备 11011102002149号