Submission #73721954


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = (1LL << 62) - (1LL << 31) - 1;

int main() {
    string S, T;
    cin >> S >> T;
    int sizeS = S.size(), sizeT = T.size();
    int ans = 0;
    int j = 0;
    for (int i = 0; i < sizeT; i++) {
        if (T[i] == 'A') {
            if (j >= sizeS) {
                ans++;
            }
            while(j < sizeS) {
                if (S[j] == 'A') {
                    j++;
                    break;
                } else {
                    ans++;
                    break;
                }
            }
        } else {
            if (j >= sizeS) {
                cout << -1 << "\n";
                return 0;
            }
            bool flag = false;
            while (j < sizeS) {
                if (S[j] == 'A') {
                    ans++;
                    j++;
                } else if (S[j] == T[i]) {
                    j++;
                    flag = true;
                    break;
                } else if (S[j] != T[i]) {
                    cout << -1 << "\n";
                    return 0;
                }
            }
            if (flag == false) {
                cout << -1 << "\n";
                return 0;
            }
        }
    }
    for (;j < sizeS; j++) {
        if (S[j] == 'A') {
            ans++;
        } else {
            cout << -1 << "\n";
            return 0;
        }
    }
    cout << ans << "\n";
    return 0;
}

Submission Info

Submission Time
Task C - Insert and Erase A
User takakan448
Language C++23 (GCC 15.2.0)
Score 300
Code Size 1540 Byte
Status AC
Exec Time 9 ms
Memory 4504 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 3436 KiB
00_sample_01.txt AC 1 ms 3500 KiB
00_sample_02.txt AC 1 ms 3540 KiB
00_sample_03.txt AC 1 ms 3592 KiB
01_random_00.txt AC 2 ms 3744 KiB
01_random_01.txt AC 4 ms 3780 KiB
01_random_02.txt AC 7 ms 4340 KiB
02_random2_00.txt AC 5 ms 3944 KiB
02_random2_01.txt AC 8 ms 4476 KiB
02_random2_02.txt AC 8 ms 4416 KiB
02_random2_03.txt AC 9 ms 4444 KiB
02_random2_04.txt AC 7 ms 4224 KiB
02_random2_05.txt AC 5 ms 4140 KiB
02_random2_06.txt AC 7 ms 4068 KiB
02_random2_07.txt AC 5 ms 3932 KiB
02_random2_08.txt AC 8 ms 4296 KiB
02_random2_09.txt AC 8 ms 4204 KiB
02_random2_10.txt AC 7 ms 4208 KiB
02_random2_11.txt AC 8 ms 4296 KiB
03_random3_00.txt AC 7 ms 4336 KiB
03_random3_01.txt AC 7 ms 4064 KiB
03_random3_02.txt AC 7 ms 4200 KiB
03_random3_03.txt AC 7 ms 4272 KiB
04_handmade_00.txt AC 1 ms 3504 KiB
04_handmade_01.txt AC 1 ms 3480 KiB
04_handmade_02.txt AC 1 ms 3656 KiB
04_handmade_03.txt AC 1 ms 3600 KiB
04_handmade_04.txt AC 8 ms 4504 KiB
04_handmade_05.txt AC 8 ms 4400 KiB
04_handmade_06.txt AC 7 ms 4440 KiB
04_handmade_07.txt AC 8 ms 4412 KiB
04_handmade_08.txt AC 4 ms 3828 KiB
04_handmade_09.txt AC 4 ms 3944 KiB