#P9922. [POI 2023/2024 R1] CzatBBB
[POI 2023/2024 R1] CzatBBB
Background
Translated from XXXI Olimpiada Informatyczna - Stage I CzatBBB。
Problem Description
You are given a string of length and a parameter . Let be the substring formed by the last letters of .
Suppose is the new string obtained by appending one new letter to .
The appending rule is as follows. For each letter , count how many times it appears in immediately after an occurrence of . The letter with the highest frequency is chosen as the new appended letter. If multiple letters have the highest frequency, choose the smallest one. If does not occur anywhere else in , then take . Finally, we extend by appending the letter to its end.
For example, let and . Then the substrings where appears together with the following letter are: , , . It most often appears with the letter , so we append to , obtaining .
Now and . The substrings where appears together with the following letter are: , . Therefore, we append to the end of .
And so on. This operation will be performed infinitely many times.
Your task is to write a program that outputs the characters from position to position of the extended string.
Input Format
The first line contains four integers , , , and .
The second line contains a string of length , consisting of lowercase English letters, representing the word .
Output Format
Output the characters from the -th to the -th position of the string , i.e. the letters located at these positions in the extended word .
11 3 12 13
abaaabababa
ba
20 3 30 40
abcdabcdabcdabcdabcd
bcdabcdabcd
见附件
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
见附件
见附件
Hint
For all testdata, , , , and the string contains only lowercase letters.
| Subtask ID | Additional Constraints | Score |
|---|---|---|
| 1 | , | 8 |
| 2 | 10 | |
| 3 | , a previous occurrence of the suffix will always exist, and the same letter will always follow each occurrence | 16 |
| 4 | a previous occurrence of the suffix will always exist, and the same letter will always follow each occurrence | 10 |
| 5 | , , the string contains only ab |
16 |
| 6 | No additional constraints | 40 |
Translated by ChatGPT 5