P10653 [ROI 2017] Memory (Day 2)

Description

Given a string $S$ of length $n$, each character is either `+` or `-`. Define a **segment** as a substring $S[l,r]$ of $S$ that satisfies the following three conditions: - $l=1$ or $S_{l-1} \ne S_l$. - $r=n$ or $S_{r+1} \ne S_r$. - $S_l=S_{l+1}=\dots=S_{r-1}=S_r$. Define one **transformation** as: - Choose two **adjacent** segments of $S$ with **different lengths**, and change every character in the shorter segment to its opposite character (`+` becomes `-`, `-` becomes `+`). Now there are $q$ queries. For each query, you are given two strings $S_i$ and $T_i$ that contain only `+` and `-` and have the same length. Please determine whether $S_i$ can be transformed into $T_i$ through several transformations.

Input Format

The first line contains an integer $q$, the number of queries. The next $q$ lines each contain two strings $S_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.

Explanation/Hint

#### Constraints Note: This problem only provides partial testdata. For the full testdata, please go to [LOJ P2770](https://loj.ac/p/2770) for judging. Let $len=\sum |S_i|$. | Subtask ID | Score | $1 \le len \le $ | Special Property | | :-----------: | :-----------: | :-----------: | :-----------: | | $1$ | $20$ | $16$ | There is no `-` in $T_i$ | | $2$ | $30$ | $10^3$ | There is no `-` in $T_i$ | | $3$ | $20$ | $10^6$ | There is no `-` in $T_i$ | | $4$ | $20$ | $10^3$ | None | | $5$ | $10$ | $10^6$ | None | Translated by ChatGPT 5