codeforces-scrape

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

1553B.md (2705B)


      1 Source: https://codeforces.com/problemset/problem/1553/B
      2 
      3 B. Reverse String
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You have a string $s$ and a chip, which you can place onto any character of this string.
     22 
     23 After placing the chip, you move it to the right several (maybe zero) times, i. e. you perform the following operation several times: if the current position of the chip is $i$, you move it to the position $i + 1$. Of course, moving the chip to the right is impossible if it is already in the last position.
     24 
     25 After moving the chip to the right, you move it to the left several (maybe zero) times, i. e. you perform the following operation several times: if the current position of the chip is $i$, you move it to the position $i - 1$. Of course, moving the chip to the left is impossible if it is already in the first position.
     26 
     27 When you place a chip or move it, you write down the character where the chip ends up after your action. For example, if $s$ is abcdef, you place the chip onto the $3$-rd character, move it to the right $2$ times and then move it to the left $3$ times, you write down the string cdedcb.
     28 
     29 You are given two strings $s$ and $t$. Your task is to determine whether it's possible to perform the described operations with $s$ so that you write down the string $t$ as a result.
     30 
     31 Input
     32 
     33 The first line contains one integer $q$ ($1 \le q \le 500$) — the number of test cases.
     34 
     35 Each test case consists of two lines. The first line contains the string $s$ ($1 \le |s| \le 500$), the second line contains the string $t$ ($1 \le |t| \le 2 \cdot |s| - 1$). Both strings consist of lowercase English characters.
     36 
     37 It is guaranteed that the sum of $|s|$ over all test cases does not exceed $500$.
     38 
     39 Output
     40 
     41 For each test case, print "YES" if you can obtain the string $t$ by performing the process mentioned in the statement with the string $s$, or "NO" if you cannot.
     42 
     43 You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 6
     51 abcdef
     52 cdedcb
     53 aaa
     54 aaaaa
     55 aab
     56 baaa
     57 ab
     58 b
     59 abcdef
     60 abcdef
     61 ba
     62 baa
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 YES
     69 YES
     70 NO
     71 YES
     72 YES
     73 NO
     74 ```
     75 
     76 Note
     77 
     78 Consider the examples.
     79 
     80 The first test case is described in the statement.
     81 
     82 In the second test case, you can place the chip on the $1$-st position, move it twice to the right, and then move it twice to the left.
     83 
     84 In the fourth test case, you can place the chip on the $2$-nd position, and then don't move it at all.
     85 
     86 In the fifth test case, you can place the chip on the $1$-st position, move it $5$ times to the right, and then finish the process.