CF928D.Autocompletion

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor.

Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboard click in order to be printed. Moreover, when Arcady has a non-empty prefix of some word on the screen, the editor proposes a possible autocompletion for this word, more precisely one of the already printed words such that its prefix matches the currently printed prefix if this word is unique. For example, if Arcady has already printed «codeforces», «coding» and «codeforces» once again, then there will be no autocompletion attempt for «cod», but if he proceeds with «code», the editor will propose «codeforces».

With a single click Arcady can follow the editor's proposal, i.e. to transform the current prefix to it. Note that no additional symbols are printed after the autocompletion (no spaces, line feeds, etc). What is the minimum number of keyboard clicks Arcady has to perform to print the entire text, if he is not allowed to move the cursor or erase the already printed symbols?

A word here is a contiguous sequence of latin letters bordered by spaces, punctuation signs and line/text beginnings/ends. Arcady uses only lowercase letters. For example, there are 20 words in «it's well-known that tic-tac-toe is a paper-and-pencil game for two players, x and o.».

阿尔卡季是一名文案编辑员。他今天的任务是使用自己最喜爱的文本编辑器,将一篇已经精心设计好的故事输入进去。

阿尔卡季逐个输入单词、标点符号和空格。每个字母及每个符号(包括换行符)都需要一次键盘点击才能被打印出来。此外,当屏幕上已存在某个单词的非空前缀时,编辑器会为此单词提供一个可能的自动补全建议:即在所有已输入过的单词中,若恰好存在唯一一个单词,其前缀与当前已输入的前缀完全匹配,则编辑器将提出该单词作为补全建议。例如,若阿尔卡季此前已输入过「codeforces」、「coding」以及再次输入了「codeforces」,那么当他输入「cod」时,编辑器不会给出任何补全建议;但若他继续输入至「code」,编辑器便会建议补全为「codeforces」。

阿尔卡季只需单击一次,即可采纳编辑器的补全建议,即将当前前缀直接替换为所建议的完整单词。注意:完成自动补全后,不会额外输出任何符号(如空格、换行符等)。若阿尔卡季不允许移动光标或删除已打印的字符,那么他要完整打印出整段文本所需的最少键盘点击次数是多少?

此处,“单词”定义为由空格、标点符号或文本/行的起始/结束位置所界定的一段连续拉丁字母序列。阿尔卡季仅使用小写字母。例如,在文本「it's well-known that tic-tac-toe is a paper-and-pencil game for two players, x and o.」中,共包含 20 个单词。

输入格式

The only line contains Arcady's text, consisting only of lowercase latin letters, spaces, line feeds and the following punctuation signs: «.», «,», «?», «!», «'» and «-». The total amount of symbols doesn't exceed 3·105. It's guaranteed that all lines are non-empty.

唯一的一行包含阿尔卡季的文本,文本仅由小写拉丁字母、空格、换行符以及以下标点符号组成:«.»、«,»、«?»、«!»、«'» 和 «-»。符号总数不超过 3⋅1053 \cdot 10^5。保证所有行均非空。

输出格式

Print a single integer — the minimum number of clicks.

输出一个整数——最小点击次数。

输入输出样例

  • 输入#1

    snow affects sports such as skiing, snowboarding, and snowmachine travel.
    snowboarding is a recreational activity and olympic and paralympic sport.

    输出#1

    141
  • 输入#2

    'co-co-co, codeforces?!'

    输出#2

    25
  • 输入#3

    thun-thun-thunder, thunder, thunder
    thunder, thun-, thunder
    thun-thun-thunder, thunder
    thunder, feel the thunder
    lightning then the thunder
    thunder, feel the thunder
    lightning then the thunder
    thunder, thunder

    输出#3

    183

说明/提示

In sample case one it's optimal to use autocompletion for the first instance of «snowboarding» after typing up «sn» and for the second instance of «snowboarding» after typing up «snowb». This will save 7 clicks.

In sample case two it doesn't matter whether to use autocompletion or not.

在样例一中,最优策略是在输入完 «sn» 后对第一个 «snowboarding» 使用自动补全,以及在输入完 «snowb» 后对第二个 «snowboarding» 使用自动补全。这将节省 7 次点击。

在样例二中,是否使用自动补全并无影响。

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

首页