C.cpp

Anonymous
c_cpp
03/01/2026 2:24 AM
808 B
24
Indexable
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

// Time Complexity: O(n)
// Memory Complexity: O(n)

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);

	string s, t; cin >> s >> t;

	string a, b;
	vector<int> ac(1), bc(1);
	for(auto &x : s) {
		if(x == 'A') ac.back()++;
		else { a.push_back(x); ac.push_back(0); }
	}
	for(auto &x : t) {
		if(x == 'A') bc.back()++;
		else { b.push_back(x); bc.push_back(0); }
	}

	if(a != b) {
		cout << -1;
		return 0;
	}

	int ans = 0;
	for(int i = 0; i < int(ac.size()); i++) {
		ans += abs(ac[i]-bc[i]);
	}
	cout << ans;


	return 0;
}
Editor is loading...
Leave a Comment