포럼
문제 ICPC00237

B. Bless You Autocorrect!

설명

Typing on phones can be tedious. It is easy to make typing mistakes, which is why most phones come with an autocorrect feature. Autocorrect not only fixes common typos, but also suggests how to finish the word while you type it. Jenny has recently been pondering how she can use this feature to her advantage, so that she can send a particular message with the minimum amount of typing.

The autocorrect feature on Jenny's phone works like this: the phone has an internal dictionary of words sorted by their frequency in the English language. Whenever a word is being typed, autocorrect suggests the most common word (if any) starting with all the letters typed so far. By pressing tab, the word being typed is completed with the autocorrect suggestion. Autocorrect can only be used after the first character of a word has been typed – it is not possible to press tab before having typed anything. If no dictionary word starts with the letters typed so far, pressing tab has no effect.

Jenny has recently noticed that it is sometimes possible to use autocorrect to her advantage even when it is not suggesting the correct word, by deleting the end of the autocorrected word. For instance, to type the word "autocorrelation", Jenny starts typing "aut", which then autocorrects to "autocorrect" (because it is such a common word these days!) when pressing tab. By deleting the last two characters ("ct") and then typing the six letters "lation", the whole word can be typed using only \(3\) ("aut") \({}+1\) (tab) \({}+2\) (backspace twice) \({}+6\) ("lation") \(= 12\) keystrokes, \(3\) fewer than typing "autocorrelation" without using autocorrect.

Given the dictionary on the phone and the words Jenny wants to type, output the minimum number of keystrokes required to type each word. The only keys Jenny can use are the letter keys, tab and backspace.

제약
입력 형식

The first line of input contains two positive integers \(n\) ($1 \le
n \le 10^5\(), the\ number\ of\ words\ in\ the\ dictionary, and \)m\( (\)1 \le
m \le 10^5\(), the\ number\ of\ words\ to\ type. Then\ follow \)n\( lines\ with\ one\ word\ per\ line, sorted\ in\ decreasing\ order\ of\ how\ common\ the\ word\ is (the\ first\ word\ is\ the\ most\ common). No\ word\ appears\ twice\ in\ the\ dictionary. Then\ follow \)m$ lines, containing the words to type.

The dictionary and the words to type only use lower case letters 'a'-'z'. The total size of the input file is at most \(1\) MB.

출력 형식

For each word to type, output a line containing the minimum number of keystrokes required to type the corresponding word.

예제 1
입력
5 5
austria
autocorrect
program
programming
computer
autocorrelation
programming
competition
zyx
austria
출력
12
4
11
3
2
예제 2
입력
5 3
yogurt
you
blessing
auto
correct
bless
you
autocorrect
출력
5
3
9
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NCPC 2016

평가 및 의견

B. Bless You Autocorrect!

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

B. Bless You Autocorrect!

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8