CF954B.String Typing
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard.
Initially, you have an empty string. Until you type the whole string, you may perform the following operation:
- add a character to the end of the string.
Besides, at most once you may perform one additional operation: copy the string and append it to itself.
For example, if you have to type string abcabca, you can type it in 7 operations if you type all the characters one by one. However, you can type it in 5 operations if you type the string abc first and then copy it and type the last character.
If you have to type string aaaaaaaaa, the best option is to type 4 characters one by one, then copy the string, and then type the remaining character.
Print the minimum number of operations you need to type the given string.
给你一个由 n 个小写拉丁字母组成的字符串 s。你需要使用键盘输入该字符串。
初始时,你拥有一个空字符串。在输入完整个字符串之前,你可以执行以下操作:
- 在字符串末尾添加一个字符。
此外,你最多可以额外执行一次如下操作:复制当前字符串,并将其追加到自身之后。
例如,若需输入字符串 abcabca,你可以逐个输入所有字符,共需 7 次操作。但更优的方法是:先输入 abc(3 次操作),然后执行一次复制操作(得到 abcabc),最后再输入最后一个字符 a(1 次操作),总共仅需 5 次操作。
又如,若需输入字符串 aaaaaaaaa,最优策略是:先逐个输入前 4 个字符(4 次操作),然后执行一次复制操作(得到 aaaaaaaa),最后再输入剩余的 1 个字符(1 次操作),共需 5 次操作。
请输出输入给定字符串所需的最少操作次数。
输入格式
The first line of the input containing only one integer number n (1 ≤ n ≤ 100) — the length of the string you have to type. The second line containing the string s consisting of n lowercase Latin letters.
输入的第一行仅包含一个整数 $ n ( 1 \leq n \leq 100 $)——表示你需要输入的字符串长度。
第二行包含字符串 $ s $,由 $ n $ 个小写拉丁字母组成。
输出格式
Print one integer number — the minimum number of operations you need to type the given string.
输出一个整数——输入给定字符串所需的最少操作次数。
输入输出样例
输入#1
7 abcabca
输出#1
5
输入#2
8 abcdefgh
输出#2
8
说明/提示
The first test described in the problem statement.
In the second test you can only type all the characters one by one.
题目描述中提到的第一个测试用例。
在第二个测试用例中,你只能逐个输入所有字符。
输入解题思路,AI测评打分。不知道怎么写?