#FT0000188. Đếm xâu được nén ngắn hơn bằng RLE (RLE)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm xâu được nén ngắn hơn bằng RLE (RLE)
RLE
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
For a lowercase English string , split it into maximal consecutive runs of equal characters. Replace a run of character repeated times by c followed by the decimal representation of (including ). For instance, aaabbcccc becomes a3b2c4, aaaaaaaaaa becomes a10, and ab becomes a1b1. Given and a prime , among all original strings of length exactly , count those whose encoded length is strictly less than , modulo . Print the count, not any encoded string.
Input
One line contains integers , where is prime.
Output
Print the number of qualifying length- strings modulo .
Subtasks
- Subtask 1 (20 points): ; , and is prime.
- Subtask 2 (30 points): ; , and is prime.
- Subtask 3 (50 points): ; , and is prime.
Examples
Example 1
Input
3 998244353
Output
26
Explanation
Each run of length encodes to one letter plus the decimal length, costing characters. Adjacent runs must have different letters: 26 choices for the first run, 25 for each subsequent run.
For , only one run of length 3 compresses from length 3 to a3 of length 2. There are exactly 26 choices for its letter.
Example 2
Input
5 998244353
Output
2626
Explanation
Each run of length encodes to one letter plus the decimal length, costing characters. Adjacent runs must have different letters: 26 choices for the first run, 25 for each subsequent run. For : a single run contributes 26 strings; two runs of lengths (1,4), (2,3), (3,2), (4,1) each contribute . Total .