提出 #73719179


ソースコード 拡げる

S = input().strip()
T = input().strip()
Sa = S.replace("A","")
Ta = T.replace("A","")
Si = 0
Ti = 0 #添え字的
Sw = [0]*(len(Sa)+1)
Tw = [0]*(len(Ta)+1) #各A以外の文字の間に、Aが何個あるか

if Sa != Ta:
    #Aを除いた文字列が合わない→無理
    print(-1)
    exit()

#実際にAの数を数えるところ
for s in S:
    if s == "A":
        Sw[Si] += 1
    else:
        Si += 1

for t in T:
    if t == "A":
        Tw[Ti] += 1
    else:
        Ti += 1

#Aの数で差分をとる
STdiff = [abs(x-y) for x,y in zip(Sw,Tw)]
print(sum(STdiff))

提出情報

提出日時
問題 C - Insert and Erase A
ユーザ Michrome
言語 Python (PyPy 3.11-v7.3.20)
得点 300
コード長 607 Byte
結果 AC
実行時間 91 ms
メモリ 130704 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 56 ms 79900 KiB
00_sample_01.txt AC 57 ms 79900 KiB
00_sample_02.txt AC 57 ms 79944 KiB
00_sample_03.txt AC 56 ms 79680 KiB
01_random_00.txt AC 58 ms 81644 KiB
01_random_01.txt AC 59 ms 83528 KiB
01_random_02.txt AC 62 ms 88848 KiB
02_random2_00.txt AC 82 ms 124704 KiB
02_random2_01.txt AC 85 ms 110392 KiB
02_random2_02.txt AC 91 ms 130468 KiB
02_random2_03.txt AC 91 ms 128272 KiB
02_random2_04.txt AC 86 ms 121900 KiB
02_random2_05.txt AC 81 ms 112576 KiB
02_random2_06.txt AC 88 ms 125828 KiB
02_random2_07.txt AC 79 ms 110096 KiB
02_random2_08.txt AC 86 ms 114544 KiB
02_random2_09.txt AC 88 ms 117604 KiB
02_random2_10.txt AC 88 ms 127372 KiB
02_random2_11.txt AC 91 ms 130704 KiB
03_random3_00.txt AC 62 ms 89116 KiB
03_random3_01.txt AC 65 ms 90816 KiB
03_random3_02.txt AC 63 ms 88264 KiB
03_random3_03.txt AC 66 ms 92160 KiB
04_handmade_00.txt AC 56 ms 79760 KiB
04_handmade_01.txt AC 56 ms 79680 KiB
04_handmade_02.txt AC 56 ms 79648 KiB
04_handmade_03.txt AC 56 ms 79688 KiB
04_handmade_04.txt AC 79 ms 118476 KiB
04_handmade_05.txt AC 66 ms 94512 KiB
04_handmade_06.txt AC 66 ms 94948 KiB
04_handmade_07.txt AC 78 ms 109208 KiB
04_handmade_08.txt AC 67 ms 96688 KiB
04_handmade_09.txt AC 66 ms 96408 KiB