#P10646. [NordicOI 2023] ChatNOI
[NordicOI 2023] ChatNOI
Background
Translated from NordicOI 2023 Problem A ChatNOI.
Problem Description
You are playing a dialogue game with your robot. The rules are as follows.
First, you are given an array of strings (all strings contain only lowercase letters) and an integer .
Define the quality of an array of strings as the minimum, over every consecutive segment of length , of the number of times that segment occurs in .
There are queries. In each query, you are given and strings.
You need to construct strings so that, after appending these constructed strings one by one after the given strings, the resulting array of strings has the maximum possible quality.
If there are multiple solutions, output any one of them.
Input Format
The first line contains two integers and .
The second line contains a sentence of words .
The third line contains an integer , meaning there are queries in total.
Then follow lines. Each line contains an integer and a substring of of length .
Output Format
For each query, you need to output the words after the given words.
13 2
ullen dullen doff kikke lane koff koffe lane bikke bane ullen dullen doff
3
1 ullen dullen
2 ullen dullen
3 ullen dullen
doff
doff kikke
doff kikke lane
8 1
buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo
1
7 buffalo
buffalo buffalo buffalo buffalo buffalo buffalo buffalo
16 1
have you not heard about the bird the bird bird bird the bird is the word
8
1 have
1 you
1 not
1 heard
1 about
1 the
1 bird
1 is
you
not
heard
about
the
bird
bird
the
Hint
This problem uses bundled testdata.
Let .
- Subtask 1 (5 points): , , , .
- Subtask 2 (7 points): , , , .
- Subtask 3 (17 points): , , , .
- Subtask 4 (18 points): , , , .
- Subtask 5 (24 points): , , , .
- Subtask 6 (16 points): , , , .
- Subtask 7 (13 points): No special constraints.
For all testdata, , , , .
Translated by ChatGPT 5