codeforces-scrape

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

1994B.md (2509B)


      1 Source: https://codeforces.com/problemset/problem/1994/B
      2 
      3 B. Fun Game
      4 
      5 time limit per test
      6 
      7 1 second
      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 Vova really loves the [XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation (denoted as $\oplus$). Recently, when he was going to sleep, he came up with a fun game.
     22 
     23 At the beginning of the game, Vova chooses two binary sequences $s$ and $t$ of length $n$ and gives them to Vanya. A binary sequence is a sequence consisting only of the numbers $0$ and $1$. Vanya can choose integers $l, r$ such that $1 \leq l \leq r \leq n$, and for all $l \leq i \leq r$ simultaneously replace $s_i$ with $s_i \oplus s_{i - l + 1}$, where $s_i$ is the $i$-th element of the sequence $s$.
     24 
     25 In order for the game to be interesting, there must be a possibility to win. Vanya wins if, with an unlimited number of actions, he can obtain the sequence $t$ from the sequence $s$. Determine if the game will be interesting for the sequences $s$ and $t$.
     26 
     27 Input
     28 
     29 Each test consists of multiple test cases. The first line contains an integer $q$ ($1 \le q \le 10^{4}$) — the number of test cases. Then follows the description of the test cases.
     30 
     31 The first line of each test case contains a single integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the length of the sequences $s$ and $t$.
     32 
     33 The second line of each test case contains a binary sequence $s$ of length $n$.
     34 
     35 The third line of each test case contains a binary sequence $t$ of length $n$.
     36 
     37 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     38 
     39 Output
     40 
     41 For each test case, output "Yes" if the game will be interesting, otherwise output "No".
     42 
     43 You can output each letter in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 6
     51 
     52 1
     53 
     54 0
     55 
     56 1
     57 
     58 7
     59 
     60 0110100
     61 
     62 0110100
     63 
     64 9
     65 
     66 100101010
     67 
     68 101111110
     69 
     70 4
     71 
     72 0011
     73 
     74 1011
     75 
     76 4
     77 
     78 0100
     79 
     80 0001
     81 
     82 8
     83 
     84 10110111
     85 
     86 01100000
     87 ```
     88 
     89 Output
     90 
     91 ```
     92 NO
     93 YES
     94 YES
     95 NO
     96 YES
     97 YES
     98 ```
     99 
    100 Note
    101 
    102 In the first test case, Vanya will not be able to change the sequence $s$ with the only possible action of choosing $l = r = 1$.
    103 
    104 In the second test case, the sequences $s$ and $t$ are already equal.
    105 
    106 In the third test case, Vanya can act as follows:
    107 
    108 1. Choose $l = 3$ and $r = 5$, then $s$ will become $\mathtt{101101010}$.
    109 2. Choose $l = 5$ and $r = 6$, then $s$ will become $\mathtt{101111010}$.
    110 3. Choose $l = 7$ and $r = 7$, then $s$ will become $\mathtt{101111110}$.