提出 #73700310


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,char> pic;
typedef vector<int> vi;
#define SZ(x) ((int)x.size())
const int mod = 1e9+7;
const int P = 998244353;

int n,m,ans = 0;
char s[300010];
char t[300010];
int main() {
	cin >> s;
	cin >> t;
	n = strlen(s);
	s[n] = '*';
	m = strlen(t);
	t[m] = '*';
	for (int i = 0,j = 0;;i++,j++){
		while (s[i] == 'A'){
			i++;
		}
		while (t[j] == 'A'){
			j++;
		}
		if (i == n && j == m){
			break;
		}
		else if (i == n || j == m){
			printf("-1");
			return 0;
		}
		else if (s[i] != t[j]){
			printf("-1");
			return 0;		
		}
	}
	int i = 0,j = 0;
	for (;i < n && j < m;i++,j++){
		while (s[i] != t[j] && t[j] == 'A'){
			j++;
			ans++;
		}
		while (s[i] != t[j] && s[i] == 'A'){
			i++;
			ans++;
		}
		if (i == n-1 && j < m-1){
			ans += m-1-j;
		}
		else if (j == m-1 && i < n-1){
			ans += n-1-i;
		}
	}
	printf("%d",ans);

    return 0;
}

提出情報

提出日時
問題 C - Insert and Erase A
ユーザ wuqize
言語 C++23 (GCC 15.2.0)
得点 300
コード長 1031 Byte
結果 AC
実行時間 11 ms
メモリ 4488 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 3792 KiB
00_sample_01.txt AC 1 ms 3488 KiB
00_sample_02.txt AC 1 ms 3792 KiB
00_sample_03.txt AC 1 ms 3632 KiB
01_random_00.txt AC 3 ms 3728 KiB
01_random_01.txt AC 4 ms 3836 KiB
01_random_02.txt AC 8 ms 4240 KiB
02_random2_00.txt AC 6 ms 4032 KiB
02_random2_01.txt AC 9 ms 4488 KiB
02_random2_02.txt AC 10 ms 4432 KiB
02_random2_03.txt AC 11 ms 4388 KiB
02_random2_04.txt AC 9 ms 4324 KiB
02_random2_05.txt AC 7 ms 4084 KiB
02_random2_06.txt AC 9 ms 4120 KiB
02_random2_07.txt AC 6 ms 4008 KiB
02_random2_08.txt AC 10 ms 4304 KiB
02_random2_09.txt AC 11 ms 4340 KiB
02_random2_10.txt AC 8 ms 4212 KiB
02_random2_11.txt AC 9 ms 4252 KiB
03_random3_00.txt AC 8 ms 4296 KiB
03_random3_01.txt AC 7 ms 4200 KiB
03_random3_02.txt AC 7 ms 4092 KiB
03_random3_03.txt AC 7 ms 4148 KiB
04_handmade_00.txt AC 1 ms 3612 KiB
04_handmade_01.txt AC 1 ms 3488 KiB
04_handmade_02.txt AC 1 ms 3580 KiB
04_handmade_03.txt AC 1 ms 3700 KiB
04_handmade_04.txt AC 9 ms 4344 KiB
04_handmade_05.txt AC 8 ms 4080 KiB
04_handmade_06.txt AC 8 ms 4292 KiB
04_handmade_07.txt AC 9 ms 4220 KiB
04_handmade_08.txt AC 5 ms 4184 KiB
04_handmade_09.txt AC 5 ms 4088 KiB