#P10653. [ROI 2017] 存储器 (Day 2)

[ROI 2017] 存储器 (Day 2)

Problem Description

Given a string SS of length nn, each character is either + or -.

Define a segment as a substring S[l,r]S[l,r] of SS that satisfies the following three conditions:

  • l=1l=1 or Sl1SlS_{l-1} \ne S_l.
  • r=nr=n or Sr+1SrS_{r+1} \ne S_r.
  • Sl=Sl+1==Sr1=SrS_l=S_{l+1}=\dots=S_{r-1}=S_r.

Define one transformation as:

  • Choose two adjacent segments of SS with different lengths, and change every character in the shorter segment to its opposite character (+ becomes -, - becomes +).

Now there are qq queries. For each query, you are given two strings SiS_i and TiT_i that contain only + and - and have the same length. Please determine whether SiS_i can be transformed into TiT_i through several transformations.

Input Format

The first line contains an integer qq, the number of queries.

The next qq lines each contain two strings Si,TiS_i,T_i, with the meaning as described above.

Output Format

For each query, output one line containing Yes or No, indicating whether the requirement can be satisfied.

3
++- +++
++-- ++++
++-+--+- ++++++++
Yes
No
Yes
3
++-+-- ++----
++-+-- +++---
-++- -++-
Yes
No
Yes

Hint

Constraints

Note: This problem only provides partial testdata. For the full testdata, please go to LOJ P2770 for judging.

Let len=Silen=\sum |S_i|.

Subtask ID Score 1len1 \le len \le Special Property
11 2020 1616 There is no - in TiT_i
22 3030 10310^3
33 2020 10610^6
44 10310^3 None
55 1010 10610^6

Translated by ChatGPT 5