| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 256 MB | 14 | 9 | 9 | 90.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$:
AAB with a contiguous substring BAA, or vice versa.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$.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 10 | There exists exactly one |
| 2 | 20 | $S_1$ consists only of |
| 3 | 70 | No additional constraints. |
1 AABBB BABBA
2
1 AAAAAABBB BBBAAAAAA
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번