codeforces-scrape

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

1553D.md (2552B)


      1 Source: https://codeforces.com/problemset/problem/1553/D
      2 
      3 D. Backspace
      4 
      5 time limit per test
      6 
      7 2 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 are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one.
     22 
     23 When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the last character you have typed among those that aren't deleted yet (or does nothing if there are no characters in the current string). For example, if $s$ is "abcbd" and you press Backspace instead of typing the first and the fourth characters, you will get the string "bd" (the first press of Backspace deletes no character, and the second press deletes the character 'c'). Another example, if $s$ is "abcaa" and you press Backspace instead of the last two letters, then the resulting text is "a".
     24 
     25 Your task is to determine whether you can obtain the string $t$, if you type the string $s$ and press "Backspace" instead of typing several (maybe zero) characters of $s$.
     26 
     27 Input
     28 
     29 The first line contains a single integer $q$ ($1 \le q \le 10^5$) — the number of test cases.
     30 
     31 The first line of each test case contains the string $s$ ($1 \le |s| \le 10^5$). Each character of $s$ is a lowercase English letter.
     32 
     33 The second line of each test case contains the string $t$ ($1 \le |t| \le 10^5$). Each character of $t$ is a lowercase English letter.
     34 
     35 It is guaranteed that the total number of characters in the strings over all test cases does not exceed $2 \cdot 10^5$.
     36 
     37 Output
     38 
     39 For each test case, print "YES" if you can obtain the string $t$ by typing the string $s$ and replacing some characters with presses of "Backspace" button, or "NO" if you cannot.
     40 
     41 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).
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 4
     49 ababa
     50 ba
     51 ababa
     52 bb
     53 aaa
     54 aaaa
     55 aababa
     56 ababa
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 YES
     63 NO
     64 NO
     65 YES
     66 ```
     67 
     68 Note
     69 
     70 Consider the example test from the statement.
     71 
     72 In order to obtain "ba" from "ababa", you may press Backspace instead of typing the first and the fourth characters.
     73 
     74 There's no way to obtain "bb" while typing "ababa".
     75 
     76 There's no way to obtain "aaaa" while typing "aaa".
     77 
     78 In order to obtain "ababa" while typing "aababa", you have to press Backspace instead of typing the first character, then type all the remaining characters.