提出 #73688647


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

void O_O() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();

    int p1 = 0, p2 = 0, ans = 0;
    while (p1 < n && p2 < m) {
        if (s[p1] != t[p2]) {
            if (s[p1] == 'A') p1++;
            else if (t[p2] == 'A') p2++;
            else return void (cout << -1);
            ans++;
        } else {
            p1++, p2++;
        }
    }

    if (p1 < n) {
        int c = 0, c2 = 0;
        while (p1 < n) c += (s[p1] != 'A'), c2++, p1++;
        if (c) return void (cout << -1);
        ans += c2;
    }

    if (p2 < m) {
        int c = 0, c2 = 0;
        while (p2 < m) c += (t[p2] != 'A'), c2++, p2++;
        if (c) return void (cout << -1);
        ans += c2;
    }
    cout << ans;
}

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

    int TC = 1;
    // cin >> TC
    while (TC--) {
        O_O();
        if (TC) cout << '\n';
    }

    return 0;
}

提出情報

提出日時
問題 C - Insert and Erase A
ユーザ Mariouma
言語 C++23 (GCC 15.2.0)
得点 300
コード長 1020 Byte
結果 AC
実行時間 3 ms
メモリ 4388 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 4
AC × 33
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3608 KiB
00_sample_01.txt AC 1 ms 3552 KiB
00_sample_02.txt AC 1 ms 3596 KiB
00_sample_03.txt AC 1 ms 3636 KiB
01_random_00.txt AC 1 ms 3972 KiB
01_random_01.txt AC 1 ms 3844 KiB
01_random_02.txt AC 2 ms 4256 KiB
02_random2_00.txt AC 2 ms 3852 KiB
02_random2_01.txt AC 3 ms 4360 KiB
02_random2_02.txt AC 3 ms 4380 KiB
02_random2_03.txt AC 3 ms 4388 KiB
02_random2_04.txt AC 3 ms 4048 KiB
02_random2_05.txt AC 2 ms 3928 KiB
02_random2_06.txt AC 3 ms 4224 KiB
02_random2_07.txt AC 2 ms 3864 KiB
02_random2_08.txt AC 3 ms 4052 KiB
02_random2_09.txt AC 3 ms 4332 KiB
02_random2_10.txt AC 2 ms 4000 KiB
02_random2_11.txt AC 3 ms 4196 KiB
03_random3_00.txt AC 2 ms 4288 KiB
03_random3_01.txt AC 3 ms 3936 KiB
03_random3_02.txt AC 2 ms 4008 KiB
03_random3_03.txt AC 2 ms 4108 KiB
04_handmade_00.txt AC 1 ms 3552 KiB
04_handmade_01.txt AC 1 ms 3432 KiB
04_handmade_02.txt AC 1 ms 3644 KiB
04_handmade_03.txt AC 1 ms 3628 KiB
04_handmade_04.txt AC 2 ms 4300 KiB
04_handmade_05.txt AC 2 ms 4244 KiB
04_handmade_06.txt AC 2 ms 4344 KiB
04_handmade_07.txt AC 2 ms 4316 KiB
04_handmade_08.txt AC 2 ms 3808 KiB
04_handmade_09.txt AC 2 ms 3912 KiB