A11373 | Maximum Questions
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya wrote down two strings $s$ of length $n$ and $t$ of length $m$ consisting of small English letters 'a' and 'b'. What is more, he knows that string $t$ has a form "abab...", namely there are letters 'a' on odd positions and letters 'b' on even positions.
Suddenly in the morning, Vasya found that somebody spoiled his string. Some letters of the string $s$ were replaced by character '?'.
Let's call a sequence of positions $i,i+1,...,i+m-1$ as occurrence of string $t$ in $s$ , if $1<=i<=n-m+1$ and $t_{1}=s_{i},t_{2}=s_{i+1},...,t_{m}=s_{i+m-1}$ .
The boy defines the beauty of the string $s$ as maximum number of disjoint occurrences of string $t$ in $s$ . Vasya can replace some letters '?' with 'a' or 'b' (letters on different positions can be replaced with different letter). Vasya wants to make some replacements in such a way that beauty of string $s$ is maximum possible. From all such options, he wants to choose one with the minimum number of replacements. Find the number of replacements he should make.
Suddenly in the morning, Vasya found that somebody spoiled his string. Some letters of the string $s$ were replaced by character '?'.
Let's call a sequence of positions $i,i+1,...,i+m-1$ as occurrence of string $t$ in $s$ , if $1<=i<=n-m+1$ and $t_{1}=s_{i},t_{2}=s_{i+1},...,t_{m}=s_{i+m-1}$ .
The boy defines the beauty of the string $s$ as maximum number of disjoint occurrences of string $t$ in $s$ . Vasya can replace some letters '?' with 'a' or 'b' (letters on different positions can be replaced with different letter). Vasya wants to make some replacements in such a way that beauty of string $s$ is maximum possible. From all such options, he wants to choose one with the minimum number of replacements. Find the number of replacements he should make.
输入格式
The first line contains a single integer $n$ ( $1<=n<=10^{5}$ ) — the length of $s$ .
The second line contains the string $s$ of length $n$ . It contains small English letters 'a', 'b' and characters '?' only.
The third line contains a single integer $m$ ( $1<=m<=10^{5}$ ) — the length of $t$ . The string $t$ contains letters 'a' on odd positions and 'b' on even positions.
The second line contains the string $s$ of length $n$ . It contains small English letters 'a', 'b' and characters '?' only.
The third line contains a single integer $m$ ( $1<=m<=10^{5}$ ) — the length of $t$ . The string $t$ contains letters 'a' on odd positions and 'b' on even positions.
输出格式
Print the only integer — the minimum number of replacements Vasya has to perform to make the beauty of string $s$ the maximum possible.
输入输出样例
输入 #1
5 bb?a? 1
输出 #1
2
输入 #2
9 ab??ab??? 3
输出 #2
2
In the first sample string $t$ has a form 'a'. The only optimal option is to replace all characters '?' by 'a'.
In the second sample using two replacements we can make string equal to "aba?aba??". It is impossible to get more than two occurrences.
In the second sample using two replacements we can make string equal to "aba?aba??". It is impossible to get more than two occurrences.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted