#P10279. [USACO24OPEN] The 'Winning' Gene S
[USACO24OPEN] The 'Winning' Gene S
Description
Note: The memory limit for this problem is 512MB, twice the default.
After years of hosting games and watching Bessie get first place over and over, Farmer John has realized that this can't be accidental. Instead, he concludes that Bessie must have winning coded into her DNA so he sets out to find this "winning" gene.
He devises a process to identify possible candidates for this "winning" gene. He takes Bessie's genome, which is a string of length where . He picks some pair where representing that the "winning" gene candidates will have length and will be found within a larger length substring. To identify the gene, he takes all length substrings from which we will call a -mer. For a given -mer, he takes all length substrings, identifies the lexicographically minimal substring as a winning gene candidate (choosing the leftmost such substring if there is a tie), and then writes down the -indexed position where that substring starts in to a set .
Since he hasn't picked and yet, he wants to know how many candidates there will be for every pair of .
For each in , help him determine the number of pairs with .
Input Format
representing the length of the string. representing the given string. All characters are guaranteed to be uppercase characters where since bovine genetics are far more advanced than ours.
Output Format
For each in , output the number of pairs with , with each number on a separate line.
8
AGTCAACG
11
10
5
4
2
2
1
1
Hint
In this test case, the third line of the output is 5 because we see that there are exactly 5 pairs of and that allow for three "winning" gene candidates. These candidates are (where is -indexed):
(4,2) -> P = [0,3,4]
(5,3) -> P = [0,3,4]
(6,4) -> P = [0,3,4]
(6,5) -> P = [0,1,3]
(6,6) -> P = [0,1,2]
To see how (4,2) leads to these results, we take all -mers
AGTC
GTCA
TCAA
CAAC
AACG
For each -mer, we identify the lexicographically minimal length 2 substring
AGTC -> AG
GTCA -> CA
TCAA -> AA
CAAC -> AA
AACG -> AA
We take the positions of all these substrings in the original string and add them to a set to get .
On the other hand, if we focus on the pair , we see that this only leads to total "winning" gene candidates. If we take all -mers and identify the lexicographically minimum length substring (using A and A' and A* to distinguish the different As), we get
AGTC -> A
GTCA' -> A'
TCA'A* -> A'
CA'A*C -> A'
A'A*CG -> A'
While both A' and A* are lexicographically minimal in the last 3 cases, the leftmost substring takes precedence so A' is counted as the only candidate in all of these cases. This means that .
SCORING:
- Inputs 2-4:
- Inputs 5-7:
- Inputs 8-16: No additional constraints.
京公网安备 11011102002149号