CF332A.Down the Hatch!

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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.

所有人都知道,贝尔兰的居民非常注重健康,尤其是学生。贝尔兰的学生们如此硬核,以至于他们只喝橙汁!

昨天,一名学生瓦夏和他的朋友们一起烧烤,并且只喝了这种健康饮品。当他们喝完第一桶果汁后,决定玩一个简单的游戏。共有 nn 人参加了这次烧烤,他们围成一个圆圈(因此每人被赋予一个从 00 到 n−1n-1 的唯一编号 bib_i)。编号为 00 的人(这次是瓦夏)首先开始游戏。游戏中的所有轮次按整数编号,从 11 开始。若第 jj 轮由编号为 bib_i 的人进行,则该人执行如下操作:

  1. 他用肘部或点头的方式指向编号为 (bi+1) mod n(b_i + 1) \bmod n 的人(其中 x mod yx \bmod y 表示 xx 除以 yy 的余数);
  2. 若 j≥4j \geq 4,且在第 j−1j-1、j−2j-2、j−3j-3 轮中行动的人,在各自轮次中所做出的动作与当前 bib_i 在第 jj 轮所做的动作完全相同,则他喝下一杯果汁;
  3. 下一轮由编号为 (bi+1) mod n(b_i + 1) \bmod n 的人进行。

在最后一轮中被指到的人不执行任何动作。

问题是:瓦夏喝下了太多果汁,已记不清游戏的目标了。不过,瓦夏保存了所有参与者(包括他自己)动作的完整记录。现在,瓦夏想知道自己若以最优策略参与游戏(其余玩家的动作保持不变),最多能喝下多少杯果汁。请帮助他。

你可以假设在任何情形下,果汁都足够所有人饮用。

输入格式

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.

第一行包含一个整数 nn(4≤n≤20004 \leq n \leq 2000)—— 表示游戏中参与者的数量。
第二行描述了实际进行的游戏过程:该行的第 ii 个字符为 'a',表示第 ii 个行动的参与者用肘部指向下一参与者;为 'b',则表示该参与者用点头的方式指向下一参与者。
游戏持续了至少 11 轮,至多 20002000 轮。

输出格式

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.

在两个样例中,瓦西娅都进行了两次操作——第 1 次和第 5 次。在第一个样例中,如果瓦西娅在第 5 次操作时用点头示意下一个人,他本可以在该次操作中喝一杯果汁。此时,操作序列将为 "abbbb"。在第二个样例中,由于第 3 次和第 4 次操作的动作不同,瓦西娅将无法喝到任何一杯果汁。

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

首页