#arc170a. A - Yet Another AB Problem
A - Yet Another AB Problem
Score: points
问题陈述
给定两个由 A 和 B 组成的字符串 和 ,它们的长度都为 。设 表示 从左数第 个字符。
你可以重复执行以下操作任意次,包括零次:
- 选择整数 和 ,使得 。将 替换为
A,将 替换为B。
确定是否可能使 等于 。如果可能,找出所需的最小操作次数。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given two strings and of length consisting of A and B. Let denote the -th character from the left of .
You can repeat the following operation any number of times, possibly zero:
- Choose integers and such that . Replace with
Aand withB.
Determine if it is possible to make equal . If it is possible, find the minimum number of operations required.
Constraints
- Each of and is a string of length consisting of
AandB. - All input numbers are integers.
Input
The input is given from Standard Input in the following format:
Output
If it is impossible to make equal , print -1.
Otherwise, print the minimum number of operations required to do so.
Sample Input 1
5
BAABA
AABAB
Sample Output 1
2
Performing the operation with and changes to AABBA.
Performing the operation with and changes to AABAB.
Thus, you can make equal with two operations. It can be proved that this is the minimum number of operations required, so the answer is .
Sample Input 2
2
AB
BA
Sample Output 2
-1
It can be proved that no matter how many operations you perform, you cannot make equal .