P28093 [洛谷] "ROI 2017 Day 2" Memory Storage
提高
题目描述

Problem Description

Given a string \( S \) with a length of \( n \), each character in \( S \) is either + or -.

A segment is defined as a substring \( S[l,r] \) 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 \).

A transformation is defined as:

  • Selecting two adjacent and different length segments in \( S \), and changing all characters in the shorter segment to their opposite character (+ to -, - to +).

There are \( q \) queries. Each query provides two strings \( S_i \) and \( T_i \), both consisting of + and - and having the same length. Determine if \( S_i \) can be transformed into \( T_i \) through multiple transformations.

Input Format

The first line contains an integer \( q \), representing the number of queries.

The next \( q \) lines each contain two strings \( S_i \) and \( T_i \), as described in the problem.

Output Format

For each query, output a line containing either Yes or No to indicate whether the transformation is possible.

Sample Input and Output

Sample Input #1

3
++- +++
++-- ++++
++-+--+- ++++++++

Sample Output #1

Yes
No
Yes

Sample Input #2

3
++-+-- ++----
++-+-- +++---
-++- -++-

Sample Output #2

Yes
No
Yes

Notes

Data Range

Note: Only partial data is provided in this problem. For complete data, please refer to LOJ P2770 for evaluation.

Let \( len = \sum |S_i| \).

Subtask Number Score \( 1 \le len \le \) Special Conditions
1 20 16 \( T_i \) contains no -
2 30 1000 \( T_i \) contains no -
3 20 10^6 \( T_i \) contains no -
4 20 1000 None
5 10 10^6 None
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 ++- +++ ++-- ++++ ++-+--+- ++++++++
样例输出
Yes No Yes