結果

問題 No.2018 X-Y-X
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2022-07-22 23:02:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,233 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 104,080 KB
最終ジャッジ日時 2023-09-17 11:45:14
合計ジャッジ時間 5,773 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,480 KB
testcase_01 AC 76 ms
71,188 KB
testcase_02 AC 77 ms
71,184 KB
testcase_03 AC 79 ms
71,260 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 145 ms
98,072 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 88 ms
78,140 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 87 ms
76,888 KB
testcase_29 AC 112 ms
80,060 KB
testcase_30 AC 104 ms
86,808 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

2018:
基本的に可逆
端は不変

最初と最後に、
A?A,B?B
が或るのは必須

反転しなければ行けない箇所に色を付けよう


"""

import sys
from sys import stdin

def change(l,r,L,R):

    ll = min(l,L)
    rr = max(r,R)

    d = r-l+1
    D = R-L+1
    dd = rr-ll+1
    
    return dd*2 - d - D


def getone(lis):

    ret = []

    for i in range(N):
        if lis[i] == 1:
            if len(ret) == 0 or ret[-1][1]+1 != i:
                ret.append( [i,i] )
            else:
                ret[-1][1] += 1

    return ret
                

N = int(stdin.readline())

S = list(stdin.readline()[:-1])
T = list(stdin.readline()[:-1])

for i in range(N):
    if S[i] == "A":
        S[i] = 0
    else:
        S[i] = 1

for i in range(N):
    if T[i] == "A":
        T[i] = 0
    else:
        T[i] = 1


if S[0] != T[0] or S[-1] != T[-1]:
    print (-1)
    sys.exit()


S01 = 0
T01 = 0

for i in range(N-1):
    if S[i] == 0 and S[i+1] == 1:
        S01 += 1
    if T[i] == 0 and T[i+1] == 1:
        T01 += 1

if S01 != T01:
    print (-1)
    sys.exit()

SG = getone(S)
TG = getone(T)

ans = 0
for i in range(len(SG)):

    ans += change(SG[i][0],SG[i][1],TG[i][0],TG[i][1])

print (ans)
0