Submission #73691776


Source Code Expand

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
using namespace std;
#define int ll

int solve() {
	string A, B; cin >> A >> B;
	int n = (int)A.size(), m = (int)B.size();

	

	int res = 0, i = 0, j = 0;
	for (; i < n and j < m; ) {
		if (A[i] == B[j]) {
			i++, j++;	
		} else if (A[i] == 'A' and B[j] != 'A') {
			res++, i++;	
		} else if (A[i] != 'A' and B[j] == 'A') {
			res++, j++;	
		} else {
			return cout << -1 << endl, 0;
		}
	}

	while (i < n) {
		if (A[i++] != 'A') return cout << -1 << endl, 0;
		else res++;
	}

	while (j < m) {
		if (B[j++] != 'A') return cout << -1 << endl, 0;
		else res++;
	}

	cout << res << endl;

	return(0);
}

signed main()
{
    _;

	int t = 1; //cin >> t;
	while (t--) {
		solve();
	}
    
    return(0);
}

Submission Info

Submission Time
Task C - Insert and Erase A
User becastal
Language C++23 (GCC 15.2.0)
Score 300
Code Size 952 Byte
Status AC
Exec Time 3 ms
Memory 4364 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 33
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt, 04_handmade_07.txt, 04_handmade_08.txt, 04_handmade_09.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3476 KiB
00_sample_01.txt AC 1 ms 3468 KiB
00_sample_02.txt AC 1 ms 3588 KiB
00_sample_03.txt AC 1 ms 3476 KiB
01_random_00.txt AC 1 ms 3924 KiB
01_random_01.txt AC 1 ms 3688 KiB
01_random_02.txt AC 2 ms 4300 KiB
02_random2_00.txt AC 1 ms 3912 KiB
02_random2_01.txt AC 2 ms 4164 KiB
02_random2_02.txt AC 2 ms 4312 KiB
02_random2_03.txt AC 3 ms 4312 KiB
02_random2_04.txt AC 2 ms 4052 KiB
02_random2_05.txt AC 2 ms 3992 KiB
02_random2_06.txt AC 2 ms 4244 KiB
02_random2_07.txt AC 2 ms 3808 KiB
02_random2_08.txt AC 3 ms 4052 KiB
02_random2_09.txt AC 3 ms 4288 KiB
02_random2_10.txt AC 2 ms 3924 KiB
02_random2_11.txt AC 2 ms 4040 KiB
03_random3_00.txt AC 2 ms 4320 KiB
03_random3_01.txt AC 3 ms 3904 KiB
03_random3_02.txt AC 2 ms 3912 KiB
03_random3_03.txt AC 1 ms 4032 KiB
04_handmade_00.txt AC 1 ms 3472 KiB
04_handmade_01.txt AC 1 ms 3492 KiB
04_handmade_02.txt AC 1 ms 3620 KiB
04_handmade_03.txt AC 1 ms 3584 KiB
04_handmade_04.txt AC 2 ms 4364 KiB
04_handmade_05.txt AC 2 ms 4300 KiB
04_handmade_06.txt AC 2 ms 4364 KiB
04_handmade_07.txt AC 2 ms 4164 KiB
04_handmade_08.txt AC 1 ms 3904 KiB
04_handmade_09.txt AC 1 ms 3816 KiB