Logo
(追記) (追記ここまで)

34463번 - AAB ↔ BAA 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB149990.000%

문제

Busy Beaver is preparing for the MIT Mystery Hunt! He is playing a game on two strings $S_1$ and $S_2,ドル each consisting only of the letters A and B. He can perform the following operation any number of times (possibly zero) on $S_1$:

  • Replace any contiguous substring AAB with a contiguous substring BAA, or vice versa.
  • Replace any contiguous substring BBA with a contiguous substring ABB, or vice versa.

Find the minimum number of operations needed to transform $S_1$ into $S_2,ドル or report that this is impossible.

입력

The first line contains a single integer $T$ (1ドル \le T \le 10^3$) --- the number of test cases.

The only line of each test case contains two space-separated strings $S_1$ and $S_2$ (1ドル\le |S_1| = |S_2|\le 10^5$) consisting of characters A and B.

The total length of all strings across all test cases does not exceed 2ドル \cdot 10^5$.

출력

For each test case, print the minimum number of operations you need to transform $S_1$ into $S_2$. If this is impossible, output $-1$.

제한

서브태스크

번호배점제한
110

There exists exactly one B in both $S_1$ and $S_2$.

220

$S_1$ consists only of As followed by Bs, and $S_2$ consists only of Bs followed by As.

370

No additional constraints.

예제 입력 1

1
AABBB BABBA

예제 출력 1

2

예제 입력 2

1
AAAAAABBB BBBAAAAAA

예제 출력 2

9

노트

In the first test case, we can perform two operations: AABBB $\to$ BAABB and then BAABB $\to$ BABBA.

출처

University > MIT > M(IT)^2 > M(IT)^2 Winter 2025 Tournament > Beginner Round 6번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /