B. Make Binary Strings Equal
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Time Limit: 0.5 s
Memory Limit: 256.0 MB
Description
You are given two binary strings s and p, both of length n. A binary string is a string consisting only of the characters '0' and '1'.
You are allowed to perform the following operation any number of times (possibly zero):
- Choose two consecutive indices \(i\) and \(i+1\) (\(1 ≤ i < n\)), and replace the substring
s[\(i..i+1\)] with either01or10.
Determine whether it is possible to transform s into p.
Input
The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each test case consists of three lines:
The first line contains an integer n (1 ≤ n ≤ 30) — the length of the strings.
The second line contains the binary string s of length n.
The third line contains the binary string p of length n.
Output
- For each test case, print
YESif it is possible to transform s into p, otherwise printNO.
Sample
| Input | Output |
|---|---|
|
|
First test case :
In the first test case, s = 1100 can be changed to p = 1010 by selecting positions 2 and 3 and replacing 10 with 01.
Hence, the answer is YES.
Fifth test case :
s = 00 and p = 10, we can directly apply one operation on positions 1 and 2 to change 00 → 10.
Hence, the answer is YES.
Happy New Year 2026
- Status
- Done
- Rule
- ACM/ICPC
- Problem
- 7
- Start at
- 2026-01-06 14:30
- End at
- 2026-01-06 17:15
- Duration
- 2.8 hour(s)
- Host
- Partic.
- 108