codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1379A.md (2964B)


      1 Source: https://codeforces.com/problemset/problem/1379/A
      2 
      3 A. Acacius and String
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Acacius is studying strings theory. Today he came with the following problem.
     22 
     23 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?
     24 
     25 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".
     26 
     27 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.
     28 
     29 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.
     30 
     31 Input
     32 
     33 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.
     34 
     35 The first line of a test case description contains a single integer $n$ ($7 \leq n \leq 50$), length of a string $s$.
     36 
     37 The second line of a test case description contains string $s$ of length $n$ consisting of lowercase English letters and question marks.
     38 
     39 Output
     40 
     41 For each test case output an answer for it.
     42 
     43 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".
     44 
     45 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.
     46 
     47 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).
     48 
     49 Example
     50 
     51 Input
     52 
     53 ```
     54 6
     55 7
     56 abacaba
     57 7
     58 ???????
     59 11
     60 aba?abacaba
     61 11
     62 abacaba?aba
     63 15
     64 asdf???f???qwer
     65 11
     66 abacabacaba
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 Yes
     73 abacaba
     74 Yes
     75 abacaba
     76 Yes
     77 abadabacaba
     78 Yes
     79 abacabadaba
     80 No
     81 No
     82 ```
     83 
     84 Note
     85 
     86 In first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.
     87 
     88 In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.
     89 
     90 In sixth example there are two occurrences of a string "abacaba" as a substring.