B. Minimum number of steps

Codeforces
IDCF804B
Time1000ms
Memory256MB
Difficulty
combinatoricsgreedyimplementationmath
English · Original
Chinese · Translation
Formal · Original
We have a string of letters '_a_' and '_b_'. We want to perform some operations on it. On each step we choose one of substrings "_ab_" in the string and replace it with the string "_bba_". If we have no "_ab_" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7. The string "_ab_" appears as a substring if there is a letter '_b_' right after the letter '_a_' somewhere in the string. ## Input The first line contains the initial string consisting of letters '_a_' and '_b_' only with length from 1 to 106. ## Output Print the minimum number of steps modulo 109 + 7. [samples] ## Note The first example: "_ab_"  →  "_bba_". The second example: "_aab_"  →  "_abba_"  →  "_bbaba_"  →  "_bbbbaa_".
我们有一个由字母 '_a_' 和 '_b_' 组成的字符串。我们希望对它执行一些操作。在每一步中,我们选择字符串中的一个子串 "_ab_",并将其替换为字符串 "_bba_"。当我们不再有任何 "_ab_" 子串时,任务完成。请输出使任务完成所需的最少操作步数,结果对 #cf_span[109 + 7] 取模。 字符串 "_ab_" 作为子串出现,当且仅当字符串中某处存在一个字母 '_a_' 后面紧跟着一个字母 '_b_'。 第一行包含一个仅由字母 '_a_' 和 '_b_' 组成的初始字符串,长度范围为 #cf_span[1] 到 #cf_span[106]。 请输出最少操作步数,结果对 #cf_span[109 + 7] 取模。 第一个例子:"_ab_" #cf_span[ → ] "_bba_"。 第二个例子:"_aab_" #cf_span[ → ] "_abba_" #cf_span[ → ] "_bbaba_" #cf_span[ → ] "_bbbbaa_"。 ## Input 第一行包含一个仅由字母 '_a_' 和 '_b_' 组成的初始字符串,长度范围为 #cf_span[1] 到 #cf_span[106]。 ## Output 请输出最少操作步数,结果对 #cf_span[109 + 7] 取模。 [samples] ## Note 第一个例子:"_ab_" #cf_span[ → ] "_bba_"。第二个例子:"_aab_" #cf_span[ → ] "_abba_" #cf_span[ → ] "_bbaba_" #cf_span[ → ] "_bbbbaa_"。
**Definitions** Let $ s \in \{a, b\}^* $ be the input string. Define an operation: replace any occurrence of the substring "ab" with "bba". **Constraints** - $ 1 \leq |s| \leq 10^6 $ - The process terminates when no substring "ab" remains. **Objective** Compute the minimum number of operations required to eliminate all occurrences of "ab" as a substring, modulo $ 10^9 + 7 $.
Samples
Input #1
ab
Output #1
1
Input #2
aab
Output #2
3
API Response (JSON)
{
  "problem": {
    "name": "B. Minimum number of steps",
    "description": {
      "content": "We have a string of letters '_a_' and '_b_'. We want to perform some operations on it. On each step we choose one of substrings \"_ab_\" in the string and replace it with the string \"_bba_\". If we have ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF804B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have a string of letters '_a_' and '_b_'. We want to perform some operations on it. On each step we choose one of substrings \"_ab_\" in the string and replace it with the string \"_bba_\". If we have ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "我们有一个由字母 '_a_' 和 '_b_' 组成的字符串。我们希望对它执行一些操作。在每一步中,我们选择字符串中的一个子串 \"_ab_\",并将其替换为字符串 \"_bba_\"。当我们不再有任何 \"_ab_\" 子串时,任务完成。请输出使任务完成所需的最少操作步数,结果对 #cf_span[109 + 7] 取模。\n\n字符串 \"_ab_\" 作为子串出现,当且仅当字符串中某处存在一个字母 '_a_' 后...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ s \\in \\{a, b\\}^* $ be the input string.  \nDefine an operation: replace any occurrence of the substring \"ab\" with \"bba\".  \n\n**Constraints**  \n- $ 1 \\leq |s| \\leq 10^6 $  \n- The ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments