A9636 | Appleman and a Game
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Appleman and Toastman like games. Today they play a game with strings with the following rules. Firstly Toastman tells Appleman two strings $s$ and $t$ both consisting only of letters 'A', 'B', 'C', 'D'. Then Appleman must build string $s$ as quickly as possible. Initially he has empty string, and in one second he can append to end of the current string any contiguous substring of $t$ .
Now, Toastman and Appleman are beginning to play the game. Toastman has already told string $t$ to Appleman, but he hasn't come up with string $s$ yet. Toastman only thinks, that he should choose string $s$ consisting of $n$ characters. Of course, he wants to find the worst string for Appleman (such string, that Appleman will spend as much time as possible during the game). Tell Toastman, how much time will Appleman spend during the game if Toastman finds the worst string for him. You can assume that Appleman plays optimally, therefore he builds any string $s$ in minimal possible time.
Now, Toastman and Appleman are beginning to play the game. Toastman has already told string $t$ to Appleman, but he hasn't come up with string $s$ yet. Toastman only thinks, that he should choose string $s$ consisting of $n$ characters. Of course, he wants to find the worst string for Appleman (such string, that Appleman will spend as much time as possible during the game). Tell Toastman, how much time will Appleman spend during the game if Toastman finds the worst string for him. You can assume that Appleman plays optimally, therefore he builds any string $s$ in minimal possible time.
输入格式
The first line contains an integer $n$ ( $1<=n<=10^{18}$ ). The second line contains string $t$ ( $1<=|t|<=10^{5}$ ). String $t$ consists of only letters 'A', 'B', 'C', 'D'. Each letter appears at least once in string $t$ .
输出格式
Print a single integer — the largest possible time Appleman needs.
输入输出样例
输入 #1
5 ABCCAD
输出 #1
5
输入 #2
5 AAABACADBABBBCBDCACBCCCDDDBDCDD
输出 #2
4
In the first example, Toastman can choose $s$ equal to "AAAAA".
In the second example, Toastman can choose $s$ equal to "DADDA".
In the second example, Toastman can choose $s$ equal to "DADDA".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted