#P8986. [北大集训 2021] 基因编辑
[北大集训 2021] 基因编辑
Background
CTT2021 D1T3
Problem Description
Humans have already developed many gene-editing techniques. One of the most traditional methods uses “restriction endonucleases” (restriction enzymes). Such enzymes can recognize specific nucleotide sequences and cut the phosphodiester bond connecting adjacent nucleotides at designated positions, producing sequence cuts called “ends”. Only matching ends can be ligated by DNA ligase.
Suppose we want to use gene fragment to replace gene fragment on a vector . In restriction-enzyme-based editing, the usual procedure is:
- Choose one restriction enzyme recognition site at each end of gene . These two recognition sites should also exist correspondingly at the two ends of gene .
- Use the restriction enzymes corresponding to the chosen recognition sites to process gene , so that the corresponding ends are generated at both ends. Purify the processed gene .
- Use the same restriction enzymes to cut the recognition sites on vector , separating gene from vector . Purify the vector with gene removed.
- Mix vector with gene , and with the help of DNA ligase, reconnect the broken phosphodiester bonds.
It is worth noting that if the two recognition sites produce the same ends after cutting, then in step 4 the vector might ligate by itself, producing a vector that contains neither gene nor ; it is also possible that gene is inserted into in reverse, also producing an incorrect vector. Therefore, in practice, restriction enzymes that produce different ends are usually chosen to process gene and vector .
In the year 3032, humans discovered an alien civilization HD1048576d that had mastered gene-editing technology. Of course, this technology only applies to the genes of alien organisms living on planet HD1048576d. The smallest unit that human gene-editing technology can recognize is a single base on a DNA sequence, while the alien civilization’s technology can recognize the smallest unit as a single noicleobase on their gene sequence. For convenience, we represent one noicleobase by a positive integer starting from . Then an alien gene sequence can be represented as a corresponding sequence of positive integers.
For an alien gene sequence of length (denote its positive-integer representation as ), the gene-editing process of HD1048576d is as follows:
- Choose an interval to be edited , i.e. replace in place the subsequence in the original sequence.
- Pick an ordered pair of indices that crosses the interval to be replaced (i.e. and ), and mass-produce the new sequence corresponding to the subsequence after editing, namely $s_i, \cdots, s_{l-1}, t_1, \cdots, t_k, s_{r+1}, \cdots, s_j$.
- Using the corresponding specific recognition tool, cut the subsequence out of the original sequence, and ligate $s_i, \cdots, s_{l-1}, t_1, \cdots, t_k, s_{r+1}, \cdots, s_j$ into the sequence, obtaining the target gene sequence.
Note that in step 2, the chosen pair of indices must correspond to a unique noicleobase combination. That is, the ordered pairs satisfying and must be unique (i.e. only ). Otherwise, the specific recognition tool may cut out other segments of the gene sequence. In addition, , otherwise the specific recognition tool may cut out only a single noicleobase.
Also, because producing the new gene sequence during replacement requires nontrivial cost, the alien civilization wants to minimize the length of the gene sequence that needs to be produced. Obviously, minimizing this length is equivalent to minimizing the length of the cut-out gene subsequence, so in practice the optimal solution is computed by minimizing the length of the cut-out gene subsequence.
Now they want to test the intelligence of human civilization, so you are selected from many high school students to solve this problem.
Input Format
The first line contains three positive integers , representing the length of the gene sequence to be edited, the left endpoint of the region to be edited, and the right endpoint of the region to be edited. It is guaranteed that and .
The second line contains positive integers , representing the gene sequence to be edited in the form of positive integers. It is guaranteed that each noicleobase index lies in .
Output Format
If there exists a gene-sequence cutting plan that satisfies the constraints of the alien civilization’s gene-editing technology, output a positive integer, meaning among all valid plans, the minimum length of the cut-out gene subsequence. Otherwise, output -1, meaning that no cutting plan satisfies the constraints.
10 4 6
2 1 4 7 4 8 3 6 4 8
6
Hint
The optimal plan is to cut out 1 4 7 4 8 3. It can be proved that there is no better cutting plan satisfying the technical constraints.
A plan with a shorter cut length is 4 7 4 8 3, but under this plan the specific recognition tool may cut out 4 8 3, causing unexpected mutations in the resulting target gene sequence. Therefore, this cutting plan does not satisfy the technical constraints.
For of the testdata, it is guaranteed that , , and .
This problem has 5 subtasks. You must pass all test points in a subtask to obtain the corresponding score for that subtask. The table below lists the data scale and properties for each subtask.
| Subtask ID | Score | Special Property | ||
|---|---|---|---|---|
The “Special Property” in the table means: are all distinct, and are all distinct.
Translated by ChatGPT 5