P1381 Word Recitation
Description
Reimu has $n$ words she wants to memorize, and she plans to remember them through a contiguous segment of an article.
The article consists of $m$ words. She wants to find a contiguous segment in the article that contains as many of her target words as possible, counting only distinct target words within the segment (duplicates count as one). Among all segments that contain the maximum number of target words, she also wants the segment to be as short as possible, so that she can spend the least time learning as many words as she can.
Input Format
The first line contains an integer $n$, followed by $n$ lines, each of which is a string of length at most $10$, representing a target word to memorize.
Then an integer $m$ follows, and then $m$ lines, each of which is a string of length at most $10$, representing a word in the article.
Output Format
Output two lines. The first line is the maximum number of target words contained in any contiguous segment of the article. The second line is the length of the shortest contiguous segment that contains this maximum number of target words.
Explanation/Hint
Constraints
- For $30\%$ of the testdata, $n \le 50$, $m \le 500$.
- For $60\%$ of the testdata, $n \le 300$, $m \le 5000$.
- For $100\%$ of the testdata, $1 \le n \le 1000$, $1 \le m \le 10^5$.
Translated by ChatGPT 5