Submission #73695307


Source Code Expand

#include<bits/stdc++.h>
// #include<atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, n) for(int  i = 0; i < (n); ++i)
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;
int gcd(int a, int b){
    if(b == 0) return a;  
    else return gcd(b, a%b);
}
struct Compare {
    bool operator()(const pair<ll, int>& a, const pair<ll, int>& b) {
        return a.first > b.first;  
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s,t; cin >> s >> t;
    int ss = s.size(), ts = t.size();
    int ans = 0;
    int idx = 0;
    for(auto x:t){
        if(idx == ss){
            if(x == 'A'){
                ans++;
                continue;
            }
            cout << -1 << endl;
            return 0;
        }
        if(x == 'A' && s[idx] != 'A'){
            ans++;
        }else{
            while(idx<ss && s[idx] != x){
                if(s[idx] != 'A'){
                    cout << -1 << endl;
                    return 0;
                }
                idx++;
                ans++;
            }
            if(s[idx] != x){
                cout << - 1 << endl;
                return 0;
            }
            idx++;
        }
    }
    for(int i = idx; i<ss;i++){
        if(s[i] != 'A'){
            cout << -1 << endl;
            return 0;
        }
        ans++;
    }
    cout << ans << endl;
}

Submission Info

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

Compile Error

./Main.cpp: In function 'int main()':
./Main.cpp:24:24: warning: unused variable 'ts' [-Wunused-variable]
   24 |     int ss = s.size(), ts = t.size();
      |                        ^~

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 3400 KiB
00_sample_01.txt AC 1 ms 3400 KiB
00_sample_02.txt AC 1 ms 3500 KiB
00_sample_03.txt AC 1 ms 3540 KiB
01_random_00.txt AC 1 ms 3860 KiB
01_random_01.txt AC 1 ms 3776 KiB
01_random_02.txt AC 2 ms 4196 KiB
02_random2_00.txt AC 2 ms 3952 KiB
02_random2_01.txt AC 2 ms 4416 KiB
02_random2_02.txt AC 3 ms 4412 KiB
02_random2_03.txt AC 3 ms 4220 KiB
02_random2_04.txt AC 3 ms 4024 KiB
02_random2_05.txt AC 2 ms 3904 KiB
02_random2_06.txt AC 3 ms 4184 KiB
02_random2_07.txt AC 2 ms 3780 KiB
02_random2_08.txt AC 3 ms 4040 KiB
02_random2_09.txt AC 3 ms 4132 KiB
02_random2_10.txt AC 2 ms 3916 KiB
02_random2_11.txt AC 2 ms 4204 KiB
03_random3_00.txt AC 2 ms 4368 KiB
03_random3_01.txt AC 3 ms 4016 KiB
03_random3_02.txt AC 2 ms 4032 KiB
03_random3_03.txt AC 2 ms 4080 KiB
04_handmade_00.txt AC 1 ms 3548 KiB
04_handmade_01.txt AC 1 ms 3552 KiB
04_handmade_02.txt AC 1 ms 3492 KiB
04_handmade_03.txt AC 1 ms 3436 KiB
04_handmade_04.txt AC 2 ms 4312 KiB
04_handmade_05.txt AC 2 ms 4268 KiB
04_handmade_06.txt AC 2 ms 4220 KiB
04_handmade_07.txt AC 2 ms 4276 KiB
04_handmade_08.txt AC 1 ms 3836 KiB
04_handmade_09.txt AC 1 ms 3952 KiB