A Sequence That Matches Front and Back
Time limit2sMemory limit128 MB
Choose how many elements to cut from the array's front so that, if the rest is a k-front-back sequence, k is as large as possible or no k exists. Return k and the cut count.
- Level
Hard8 of 10
- Topics
- Array, String matching, Binary search
- Solved
- No attempts yet
Problem
A sequence is called a k-front-back sequence if it satisfies the following property.
When a sequence is a k-front-back sequence, the maximum value of k, denoted , is called the front-back coefficient of the sequence.
To make the front and back of a sequence match, we can cut off a contiguous prefix of the sequence.
For example, removing from yields .
How much of the prefix of the given sequence should we cut off to maximize the front-back coefficient? There may be more than one way to do this. The cutting methods also include "cutting nothing."
Input
The first line contains . ()
The second line contains integers separated by spaces. ()
Output
If cutting a prefix can produce a front-back sequence, output the maximum front-back coefficient after such a cut and the number of ways to make that cut, separated by a space. If no cut produces a front-back coefficient, output -1.