#P16236. [蓝桥杯 2026 省 B] LQ 聚合
[蓝桥杯 2026 省 B] LQ 聚合
Problem Description
In the year 2056, an expedition team discovered a signal transmission tower deep inside a crater on the far side of the Moon. Its core console is continuously flashing a particle sequence of length .
Each position in the sequence is strictly defined as an -type particle, a -type particle, or an unknown state , blurred by the erosion of time. These particles will be injected into the reaction field one by one, and the stability of the field depends on the number of “ aggregations” in the sequence. This number is defined as the count of all pairs satisfying , where the -th position is and the -th position is .
To restart this dormant giant tower, the expedition team needs to repair all in the sequence into definite or .
Now, please compute the maximum possible number of “ aggregations” among all possible repair plans.
Input Format
The first line contains an integer , representing the length of the particle sequence.
The second line contains a string of length , consisting only of characters L, Q, and ?, representing the currently detected state of the particle sequence.
Output Format
Output one integer, representing the maximum number of “ aggregations” that can be obtained after replacing all ? with L or Q.
5
??L??
6
Hint
Sample Explanation
One optimal strategy is to repair the sequence into LLLQQ. Then, the first L and the last Q can produce aggregations in total.
Test Case Scale and Assumptions
For of the test cases, the number of ? in the string does not exceed .
For all test cases, .
Translated by ChatGPT 5