A13638 | Acacius and String
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Acacius is studying strings theory. Today he came with the following problem.
You are given a string $s$ of length $n$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?
Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".
Occurrence of a string $t$ of length $m$ in the string $s$ of length $n$ as a substring is a index $i$ ( $1 \leq i \leq n - m + 1$ ) such that string $s[i..i+m-1]$ consisting of $m$ consecutive symbols of $s$ starting from $i$ -th equals to string $t$ . For example string "ababa" has two occurrences of a string "aba" as a substring with $i = 1$ and $i = 3$ , but there are no occurrences of a string "aba" in the string "acba" as a substring.
Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once.
You are given a string $s$ of length $n$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?
Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".
Occurrence of a string $t$ of length $m$ in the string $s$ of length $n$ as a substring is a index $i$ ( $1 \leq i \leq n - m + 1$ ) such that string $s[i..i+m-1]$ consisting of $m$ consecutive symbols of $s$ starting from $i$ -th equals to string $t$ . For example string "ababa" has two occurrences of a string "aba" as a substring with $i = 1$ and $i = 3$ , but there are no occurrences of a string "aba" in the string "acba" as a substring.
Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once.
输入格式
First line of input contains an integer $T$ ( $1 \leq T \leq 5000$ ), number of test cases. $T$ pairs of lines with test case descriptions follow.
The first line of a test case description contains a single integer $n$ ( $7 \leq n \leq 50$ ), length of a string $s$ .
The second line of a test case description contains string $s$ of length $n$ consisting of lowercase English letters and question marks.
The first line of a test case description contains a single integer $n$ ( $7 \leq n \leq 50$ ), length of a string $s$ .
The second line of a test case description contains string $s$ of length $n$ consisting of lowercase English letters and question marks.
输出格式
For each test case output an answer for it.
In case if there is no way to replace question marks in string $s$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No".
Otherwise output "Yes" and in the next line output a resulting string consisting of $n$ lowercase English letters. If there are multiple possible strings, output any.
You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
In case if there is no way to replace question marks in string $s$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No".
Otherwise output "Yes" and in the next line output a resulting string consisting of $n$ lowercase English letters. If there are multiple possible strings, output any.
You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
输入输出样例
输入 #1
6 7 abacaba 7 ??????? 11 aba?abacaba 11 abacaba?aba 15 asdf???f???qwer 11 abacabacaba
输出 #1
Yes abacaba Yes abacaba Yes abadabacaba Yes abacabadaba No No
In first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.
In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.
In sixth example there are two occurrences of a string "abacaba" as a substring.
In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.
In sixth example there are two occurrences of a string "abacaba" as a substring.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted