CF1003F.Abbreviation

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a text consisting of nn space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. wiw_i is the ii-th word of text. All words consist only of lowercase Latin letters.

Let's denote a segment of words w[i..j]w[i..j] as a sequence of words wi,wi+1,…,wjw_i, w_{i + 1}, \dots, w_j. Two segments of words w[i1..j1]w[i_1 .. j_1] and w[i2..j2]w[i_2 .. j_2] are considered equal if j1−i1=j2−i2j_1 - i_1 = j_2 - i_2, j1≥i1j_1 \ge i_1, j2≥i2j_2 \ge i_2, and for every t∈[0,j1−i1]t \in [0, j_1 - i_1] wi1+t=wi2+tw_{i_1 + t} = w_{i_2 + t}. For example, for the text "to be or not to be" the segments w[1..2]w[1..2] and w[5..6]w[5..6] are equal, they correspond to the words "to be".

An abbreviation is a replacement of some segments of words with their first uppercase letters. In order to perform an abbreviation, you have to choose at least two non-intersecting equal segments of words, and replace each chosen segment with the string consisting of first letters of the words in the segment (written in uppercase). For example, for the text "a ab a a b ab a a b c" you can replace segments of words w[2..4]w[2..4] and w[6..8]w[6..8] with an abbreviation "AAA" and obtain the text "a AAA b AAA b c", or you can replace segments of words w[2..5]w[2..5] and w[6..9]w[6..9] with an abbreviation "AAAB" and obtain the text "a AAAB AAAB c".

What is the minimum length of the text after at most one abbreviation?

给你一段由 nn 个以空格分隔的单词组成的文本。任意两个相邻单词之间恰好有一个空格字符,且文本开头没有空格,结尾也没有空格。文本的长度定义为其中字母和空格的总个数。记 wiw_i 为文本中第 ii 个单词。所有单词均由小写拉丁字母组成。

我们用 w[i..j]w[i..j] 表示从第 ii 个单词到第 jj 个单词(含端点)构成的单词段,即序列 wi,wi+1,…,wjw_i, w_{i + 1}, \dots, w_j。两个单词段 w[i1..j1]w[i_1 .. j_1] 和 w[i2..j2]w[i_2 .. j_2] 被视为相等,当且仅当满足:

  • j1−i1=j2−i2j_1 - i_1 = j_2 - i_2,
  • j1≥i1j_1 \ge i_1 且 j2≥i2j_2 \ge i_2,
  • 对每个 t∈[0,j1−i1]t \in [0, j_1 - i_1],均有 wi1+t=wi2+tw_{i_1 + t} = w_{i_2 + t}。

例如,对文本 "to be or not to be",单词段 w[1..2]w[1..2] 与 w[5..6]w[5..6] 相等,均对应单词 "to be"。

缩写(abbreviation) 是指将某些单词段替换为其各单词首字母的大写形式。要执行一次缩写操作,你必须选择至少两个互不相交且彼此相等的单词段,并将每个被选中的单词段替换为一个字符串——该字符串由该段中各单词的首字母(大写)依次拼接而成。例如,对文本 "a ab a a b ab a a b c",你可以将单词段 w[2..4]w[2..4] 和 w[6..8]w[6..8] 替换为缩写 "AAA",得到新文本 "a AAA b AAA b c";或者将单词段 w[2..5]w[2..5] 和 w[6..9]w[6..9] 替换为缩写 "AAAB",得到新文本 "a AAAB AAAB c"。

在最多执行一次缩写操作的前提下,文本可能达到的最小长度是多少?

输入格式

The first line of the input contains one integer nn (1≤n≤3001 \le n \le 300) — the number of words in the text.

The next line contains nn space-separated words of the text w1,w2,…,wnw_1, w_2, \dots, w_n. Each word consists only of lowercase Latin letters.

It is guaranteed that the length of text does not exceed 10510^5.

输入的第一行包含一个整数 nn(1≤n≤3001 \le n \le 300)—— 表示文本中单词的个数。

下一行包含 nn 个由空格分隔的文本单词 w1,w2,…,wnw_1, w_2, \dots, w_n。每个单词仅由小写拉丁字母组成。

保证文本总长度不超过 10510^5。

输出格式

Print one integer — the minimum length of the text after at most one abbreviation.

输出一个整数——最多进行一次缩写后文本的最小长度。

输入输出样例

  • 输入#1

    6
    to be or not to be

    输出#1

    12
  • 输入#2

    10
    a ab a a b ab a a b c

    输出#2

    13
  • 输入#3

    6
    aa bb aa aa bb bb

    输出#3

    11

说明/提示

In the first example you can obtain the text "TB or not TB".

In the second example you can obtain the text "a AAAB AAAB c".

In the third example you can obtain the text "AB aa AB bb".

在第一个例子中,你可以得到文本“TB or not TB”。

在第二个例子中,你可以得到文本“a AAAB AAAB c”。

在第三个例子中,你可以得到文本“AB aa AB bb”。

输入解题思路,AI测评打分。不知道怎么写?

首页