Submission #73721170


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
int main(){
    string s, t; cin >> s >> t;
    map<char,int> ft, fs;
    bool fat = false, fas = false;
    for(char i: t){
        if(i == 'A') continue;
        if(ft.count(i)) ft[i]++;
        else ft[i] = 1;
        fat = true;
    }
    for(char i: s){
        if(i == 'A') continue;
        if(ft.count(i)){
            if(fs.count(i)) fs[i]++;
            else fs[i] = 1;
            if(fs[i] > ft[i]){
                cout <<"-1\n";
                return 0;
            }
        } else {
            cout <<"-1\n";
            return 0;
        }
        fas = true;
    }
    if(!(fas) && fat){
        cout <<"-1\n";
        return 0;
    }
    vector<int> vs(1), vt(1);
    int ind = 0;
    for(char i: s){
        if(i == 'A') vs[ind]++;
        else if(fs[i] != ft[i]){
            cout <<"-1\n";
            return 0;
        } else {
            vs.push_back(0);
            ind++;
        }
    }
    ind = 0;
    for(char i: t){
        if(i == 'A') vt[ind]++;
        else if(!fs.count(i) || fs[i] != ft[i]){
            cout <<"-1\n";
            return 0;
        }
        else {
            vt.push_back(0);
            ind++;
        }
    }
    int res = 0;
    for(int i = 0; i <= ind; i++){
        res += abs(vs[i] - vt[i]);
    }
    cout << res << "\n";
    return 0;
}

Submission Info

Submission Time
Task C - Insert and Erase A
User mg00s
Language C++ IOI-Style(GNU++20) (GCC 14.2.0)
Score 0
Code Size 1408 Byte
Status WA
Exec Time 47 ms
Memory 6592 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 4
AC × 32
WA × 1
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 1704 KiB
00_sample_01.txt AC 1 ms 1704 KiB
00_sample_02.txt AC 1 ms 1704 KiB
00_sample_03.txt AC 1 ms 1704 KiB
01_random_00.txt AC 7 ms 1960 KiB
01_random_01.txt AC 4 ms 2088 KiB
01_random_02.txt AC 28 ms 2788 KiB
02_random2_00.txt AC 34 ms 4476 KiB
02_random2_01.txt AC 13 ms 2788 KiB
02_random2_02.txt AC 47 ms 4804 KiB
02_random2_03.txt AC 44 ms 4804 KiB
02_random2_04.txt AC 32 ms 4280 KiB
02_random2_05.txt AC 16 ms 2836 KiB
02_random2_06.txt AC 39 ms 4952 KiB
02_random2_07.txt AC 11 ms 2656 KiB
02_random2_08.txt AC 21 ms 3416 KiB
02_random2_09.txt AC 28 ms 3472 KiB
02_random2_10.txt AC 39 ms 4556 KiB
02_random2_11.txt AC 46 ms 4764 KiB
03_random3_00.txt AC 27 ms 2784 KiB
03_random3_01.txt AC 15 ms 2404 KiB
03_random3_02.txt AC 22 ms 2600 KiB
03_random3_03.txt WA 32 ms 4332 KiB
04_handmade_00.txt AC 1 ms 1704 KiB
04_handmade_01.txt AC 1 ms 1704 KiB
04_handmade_02.txt AC 0 ms 1704 KiB
04_handmade_03.txt AC 1 ms 1704 KiB
04_handmade_04.txt AC 18 ms 6592 KiB
04_handmade_05.txt AC 8 ms 2784 KiB
04_handmade_06.txt AC 9 ms 2784 KiB
04_handmade_07.txt AC 9 ms 2716 KiB
04_handmade_08.txt AC 5 ms 2344 KiB
04_handmade_09.txt AC 5 ms 2344 KiB