#P6254. [ICPC 2019 WF] Circular DNA

[ICPC 2019 WF] Circular DNA

题目描述

You have an internship with a bioinformatics research group studying DNA. A single strand of DNA consists of many genes, which fall into different categories called gene types. Gene types are delimited by specific nucleotide sequences known as gene markers. Each gene type i has a unique start marker si\texttt s_i and a unique end marker ei\texttt e_i . After many dirty jobs (growing bacteria, cell extraction, protein engineering,and so on), your research group can convert DNA into a form consisting of only the gene markers, removing all the genetic material lying between the markers.

Your research group came up with the interesting hypothesis that gene interpretation depends on whether the markers of some gene types form properly nested structures. To decide whether markers of gene type ii form a proper nesting in a given sequence of markers ww, one needs to consider the subsequence of ww containing only the markers of gene type ii (si\texttt s_i and ei\texttt e_i), leaving none of them out. The following (and only the following) are considered to be properly nested structures:

  • siei\texttt s_i \texttt e_i
  • siNei\texttt s_i N \texttt e_i, where NN is a properly nested structure
  • ABAB, where AA and BB are properly nested structures

Given your computing background, you were assigned to investigate this property, but there is one further complication. Your group is studying a specific type of DNA called circular DNA, which is DNA that forms a closed loop. To study nesting in circular DNA, it is necessary to cut the loop at some location, which results in a unique sequence of markers (the direction of reading is fixed by molecular properties). Whether a gene type ii forms a proper nesting now also depends on where the circular DNA is cut. Your task is to find the cutting location that maximizes the number of gene types that form a properly nested structure. Figure D.1 shows an example corresponding to Sample Input 1. The indicated cut results in the markers for gene type 1 being properly nested.

输入格式

The first line of input contains an integer nn (1n1061 \leq n \leq 10^6), the length of the DNA. The next line contains the DNA sequence, that is, nn markers. Each marker is a character cc followed by an integer ii, where c{s,e}c \in \{\texttt s, \texttt e\} specifies whether it is a start or an end marker and ii (1i1061 \leq i \leq 10^6) is the gene type of the marker. The given DNA sequence has been obtained from the circular DNA by cutting at an arbitrary location.

输出格式

Output one line with two integers pp and mm, where pp is the cutting position that maximizes the number of different gene types that form a proper nesting, and mm is this maximum number of gene types. The DNA is cut just before the pthp^{\text{th}} input marker (for instance, the cut shown in Figure D.1 has p=3p = 3). If more than one cutting position yields the same maximum value of mm, output the smallest pp that does so.

9
e1 e1 s1 e2 s1 s2 e42 e1 s1
3 1
8
s1 s1 e3 e1 s3 e1 e3 s3
8 2

提示

Source: ICPC 2019 World Finals.