Same Suffix Array
Time limit2sMemory limit256 MB
Count the strings that differ from the given length N string in exactly one position and keep the same suffix array.
- Level
Hard9 of 10
- Topics
- String, String matching, Sorting
- Solved
- No attempts yet
Problem
You are given a string of length . Count the strings that differ from it in exactly one position and have the same suffix array.
The alphabet has symbols, so each character is written as an integer from to . A larger integer comes later in lexicographic order.
The suffix array of a string of length is built by sorting the suffixes of in lexicographic order and listing the starting position of each suffix in that order.
Input
The first line contains and , separated by a space (). is the length of the string and is the number of symbols in the alphabet.
The second line contains integers, the characters of the string in order, separated by spaces. Each integer is between and .
Output
Print the number of strings that differ from the given string in exactly one position and have the same suffix array.
Hint
In the first example, 2 1 is the only string that satisfies the condition.