#P13971. [VKOSHP 2024] Exploration Robots
[VKOSHP 2024] Exploration Robots
题目描述
The field for testing the robots consists of cells numbered by integers to from left to right. Each cell contains a letter of the English alphabet; reading the letters from the first to the -th cell forms the string .
There are two robots that can move across the field, with the following conditions:
- The robots know the string ;
- The robots can freely exchange information;
- The robots always know the distance between them, as well as which robot is to the left and which is to the right;
- Each of the two robots can read the letter that is directly below it;
In one step, a robot can, after exchanging information with the other robot, move to an adjacent cell to the left or to an adjacent cell to the right. If a robot attempts to move left of the first cell or right of the -th cell, it is destroyed.
The scientists want to conduct experiments, in the -th of which the first robot is placed at position , and the second at position . The goal of the robots in each experiment is to visit as many different cells as possible. For each experiment, it is necessary to determine the maximum number of cells that the robots can visit without risking destruction.
输入格式
The first line contains a pair of numbers and () --- the number of cells and the number of experiments.
The second line contains the string of length , consisting of lowercase Latin letters.
In the following lines, pairs of numbers , are given ().
输出格式
For each experiment, output the maximum number of different cells that the robots can visit.
10 4
aabaabbaab
4 5
8 5
2 3
1 1
3
10
3
3
提示
Consider the last experiment in the example. The robots start at the same point and see the letter . They understand that moving left is dangerous, as it may lead to the destruction of the robot. However, moving right is safe, as the last letter of the string is . One or both robots move to the right until they reach the letter . Upon reaching the letter , the robots know that the string before it was , which could be either the beginning or the end of the string; they cannot go beyond its limits without risking destruction, so they managed to visit a total of cells.