#P1381. 单词背诵

    ID: 376 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>模拟字符串福建省历届夏令营哈希,HASH双指针,尺取法,two-pointer

单词背诵

Description

Reimu has nn words she wants to memorize, and she plans to remember them through a contiguous segment of an article.

The article consists of mm 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 nn, followed by nn lines, each of which is a string of length at most 1010, representing a target word to memorize.

Then an integer mm follows, and then mm lines, each of which is a string of length at most 1010, 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.

3
hot
dog
milk
5
hot
dog
dog
milk
hot

3
3

Hint

Constraints

  • For 30%30\% of the testdata, n50n \le 50, m500m \le 500.
  • For 60%60\% of the testdata, n300n \le 300, m5000m \le 5000.
  • For 100%100\% of the testdata, 1n10001 \le n \le 1000, 1m1051 \le m \le 10^5.

Translated by ChatGPT 5