luogu#P4925. [1007] Scarlet的字符串不可能这么可爱
[1007] Scarlet的字符串不可能这么可爱
Problem Description
Scarlet wants to construct a string with an alphabet size of and length , such that it has no palindromic contiguous substring with length greater than .
It seems there are too many such strings, so Scarlet casually adds a restriction: she fixes the -th character of the string to be .
Now Scarlet cannot solve it. Please help her compute how many strings satisfy the conditions. As usual, you only need to output the answer modulo .
Input Format
The first line contains three integers and , representing the alphabet size, the string length, and the modulus.
The second line contains two integers , describing the restriction given by Scarlet.
Note: means that in this test case Scarlet kindly did not add any restriction.
Output Format
Output one integer in a single line, representing the number of valid strings modulo .
3 3 233
1 1
2
Hint
Alphabet size: the number of distinct characters in a string. For example, if the alphabet size is , you may assume the string consists only of the three letters “A”, “B”, and “C”.
Sample explanation: if the first character is fixed to A, then the valid strings are ABC and ACB. The string AAB contains the palindromic substring AA, and ACA itself is a palindrome, and so on.
Constraints for of the testdata: .
Constraints for another of the testdata: .
Constraints for of the testdata: $1\leq k, L\leq 10^{18}, 0\leq s\leq L, 1\leq w\leq k, 1\leq p\leq 10^9$.
Translated by ChatGPT 5