A9123 | Down the Hatch!
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to play a simple game. All $n$ people who came to the barbecue sat in a circle (thus each person received a unique index $b_{i}$ from 0 to $n-1$ ). The person number 0 started the game (this time it was Vasya). All turns in the game were numbered by integers starting from 1. If the $j$ -th turn was made by the person with index $b_{i}$ , then this person acted like that:
1. he pointed at the person with index $(b_{i}+1) mod n$ either with an elbow or with a nod ( $x mod y$ is the remainder after dividing $x$ by $y$ );
2. if $j>=4$ and the players who had turns number $j-1$ , $j-2$ , $j-3$ , made during their turns the same moves as player $b_{i}$ on the current turn, then he had drunk a glass of juice;
3. the turn went to person number $(b_{i}+1) mod n$ .
The person who was pointed on the last turn did not make any actions.
The problem was, Vasya's drunk too much juice and can't remember the goal of the game. However, Vasya's got the recorded sequence of all the participants' actions (including himself). Now Vasya wants to find out the maximum amount of juice he could drink if he played optimally well (the other players' actions do not change). Help him.
You can assume that in any scenario, there is enough juice for everybody.
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to play a simple game. All $n$ people who came to the barbecue sat in a circle (thus each person received a unique index $b_{i}$ from 0 to $n-1$ ). The person number 0 started the game (this time it was Vasya). All turns in the game were numbered by integers starting from 1. If the $j$ -th turn was made by the person with index $b_{i}$ , then this person acted like that:
1. he pointed at the person with index $(b_{i}+1) mod n$ either with an elbow or with a nod ( $x mod y$ is the remainder after dividing $x$ by $y$ );
2. if $j>=4$ and the players who had turns number $j-1$ , $j-2$ , $j-3$ , made during their turns the same moves as player $b_{i}$ on the current turn, then he had drunk a glass of juice;
3. the turn went to person number $(b_{i}+1) mod n$ .
The person who was pointed on the last turn did not make any actions.
The problem was, Vasya's drunk too much juice and can't remember the goal of the game. However, Vasya's got the recorded sequence of all the participants' actions (including himself). Now Vasya wants to find out the maximum amount of juice he could drink if he played optimally well (the other players' actions do not change). Help him.
You can assume that in any scenario, there is enough juice for everybody.
输入格式
The first line contains a single integer $n$ ( $4<=n<=2000$ ) — the number of participants in the game. The second line describes the actual game: the $i$ -th character of this line equals 'a', if the participant who moved $i$ -th pointed at the next person with his elbow, and 'b', if the participant pointed with a nod. The game continued for at least 1 and at most $2000$ turns.
输出格式
Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well.
输入输出样例
输入 #1
4 abbba
输出 #1
1
输入 #2
4 abbab
输出 #2
0
In both samples Vasya has got two turns — 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the moves performed during turns 3 and 4 are different.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted