結果

問題 No.2018 X-Y-X
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-07-23 10:23:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 548 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 125,308 KB
最終ジャッジ日時 2023-09-18 04:37:12
合計ジャッジ時間 5,362 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,232 KB
testcase_01 AC 70 ms
71,308 KB
testcase_02 AC 72 ms
71,568 KB
testcase_03 AC 70 ms
71,256 KB
testcase_04 AC 70 ms
71,424 KB
testcase_05 AC 72 ms
71,112 KB
testcase_06 AC 119 ms
107,524 KB
testcase_07 AC 118 ms
108,924 KB
testcase_08 AC 124 ms
119,732 KB
testcase_09 AC 125 ms
119,536 KB
testcase_10 AC 111 ms
92,792 KB
testcase_11 AC 115 ms
96,908 KB
testcase_12 AC 119 ms
97,620 KB
testcase_13 AC 118 ms
108,376 KB
testcase_14 AC 120 ms
105,724 KB
testcase_15 AC 124 ms
113,024 KB
testcase_16 AC 109 ms
97,856 KB
testcase_17 AC 121 ms
107,764 KB
testcase_18 AC 106 ms
90,676 KB
testcase_19 AC 111 ms
107,064 KB
testcase_20 AC 109 ms
107,448 KB
testcase_21 AC 115 ms
103,536 KB
testcase_22 AC 114 ms
103,240 KB
testcase_23 AC 71 ms
71,120 KB
testcase_24 AC 137 ms
125,308 KB
testcase_25 AC 131 ms
117,552 KB
testcase_26 AC 132 ms
124,308 KB
testcase_27 AC 93 ms
88,240 KB
testcase_28 AC 71 ms
71,432 KB
testcase_29 AC 91 ms
83,556 KB
testcase_30 AC 71 ms
71,396 KB
testcase_31 AC 111 ms
94,432 KB
testcase_32 AC 119 ms
105,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = input()
T = input()
if S[0] != T[0] or S[-1] != T[-1]:
    print(-1)
    exit()
S = [ord(s)-ord("A") for s in S]
T = [ord(t)-ord("A") for t in T]

S2 = []
T2 = []

for i in range(n-1):
    S2.append(S[i]^S[i+1])
    T2.append(T[i]^T[i+1])


for i in range(1,n-1,2):
    S2[i] ^= 1
    T2[i] ^= 1

if sum(S2) != sum(T2):
    print(-1)
    exit()

Sone = []
Tone = []
for i in range(n-1):
    if S2[i]:
        Sone.append(i)
    if T2[i]:
        Tone.append(i)

ans = 0
for s,t in zip(Sone,Tone):
    ans += abs(s-t)
print(ans)
0