CF1129C.Morse Code

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In Morse code, an letter of English alphabet is represented as a string of some length from 11 to 44. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task, we will represent a dot with a "0" and a dash with a "1".

Because there are 21+22+23+24=302^1+2^2+2^3+2^4 = 30 strings with length 11 to 44 containing only "0" and/or "1", not all of them correspond to one of the 2626 English letters. In particular, each string of "0" and/or "1" of length at most 44 translates into a distinct English letter, except the following four strings that do not correspond to any English alphabet: "0011", "0101", "1110", and "1111".

You will work with a string SS, which is initially empty. For mm times, either a dot or a dash will be appended to SS, one at a time. Your task is to find and report, after each of these modifications to string SS, the number of non-empty sequences of English letters that are represented with some substring of SS in Morse code.

Since the answers can be incredibly tremendous, print them modulo 109+710^9 + 7.

在莫尔斯电码中,英文字母被表示为长度为 11 至 44 的字符串。此外,每个英文字母的莫尔斯码表示仅由“点”(dot)和“划”(dash)组成。在本题中,我们用字符 "0" 表示一个“点”,用 "1" 表示一个“划”。

由于仅含 "0" 和/或 "1"、且长度在 11 到 44 之间的字符串共有 21+22+23+24=302^1+2^2+2^3+2^4 = 30 个,但英文字母仅有 2626 个,因此并非所有这 3030 个字符串都对应某个英文字母。具体而言,所有长度不超过 44 的 "0"/"1" 字符串均唯一对应一个英文字母,除以下四个字符串外:"0011"、"0101"、"1110" 和 "1111" —— 它们不对应任何英文字母。

你将处理一个初始为空的字符串 SS。接下来共进行 mm 次操作,每次操作向 SS 末尾追加一个 "0"(点)或 "1"(划)。你的任务是:在每次向 SS 追加字符后,找出并报告 SS 中有多少个非空的英文字母序列,使得该序列可由 SS 的某个子串以莫尔斯码方式表示。

由于答案可能极其巨大,请对 109+710^9 + 7 取模后输出。

输入格式

The first line contains an integer mm (1≤m≤3 0001 \leq m \leq 3\,000) — the number of modifications to SS.

Each of the next mm lines contains either a "0" (representing a dot) or a "1" (representing a dash), specifying which character should be appended to SS.

第一行包含一个整数 mm(1≤m≤3 0001 \leq m \leq 3\,000)—— 表示对字符串 SS 进行修改的次数。

接下来的 mm 行中,每行包含一个字符:"0"(代表点)或 "1"(代表划),表示应将该字符追加到 SS 的末尾。

输出格式

Print mm lines, the ii-th of which being the answer after the ii-th modification to SS.

输出 mm 行,其中第 ii 行表示对字符串 SS 进行第 ii 次修改后的答案。

输入输出样例

  • 输入#1

    3
    1
    1
    1

    输出#1

    1
    3
    7
  • 输入#2

    5
    1
    0
    1
    0
    1

    输出#2

    1
    4
    10
    22
    43
  • 输入#3

    9
    1
    1
    0
    0
    0
    1
    1
    0
    1

    输出#3

    1
    3
    10
    24
    51
    109
    213
    421
    833

说明/提示

Let us consider the first sample after all characters have been appended to SS, so S is "111".

As you can see, "1", "11", and "111" all correspond to some distinct English letter. In fact, they are translated into a 'T', an 'M', and an 'O', respectively. All non-empty sequences of English letters that are represented with some substring of SS in Morse code, therefore, are as follows.

  1. "T" (translates into "1")
  2. "M" (translates into "11")
  3. "O" (translates into "111")
  4. "TT" (translates into "11")
  5. "TM" (translates into "111")
  6. "MT" (translates into "111")
  7. "TTT" (translates into "111")

Although unnecessary for this task, a conversion table from English alphabets into Morse code can be found here.

我们考虑第一个样例中所有字符都追加到 SS 后的情形,此时 SS 为 "111"。

如您所见,"1"、"11" 和 "111" 均对应某个不同的英文字母。事实上,它们分别被翻译为 'T'、'M' 和 'O'。因此,所有能用 SS 的某个子串在摩尔斯电码中表示的非空英文字母序列如下所示:

  1. "T"(翻译为 "1")
  2. "M"(翻译为 "11")
  3. "O"(翻译为 "111")
  4. "TT"(翻译为 "11")
  5. "TM"(翻译为 "111")
  6. "MT"(翻译为 "111")
  7. "TTT"(翻译为 "111")

尽管本题无需此信息,但英文字母到摩尔斯电码的转换表可在此处找到:https://en.wikipedia.org/wiki/Morse_code

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

首页