結果

問題 No.2018 X-Y-X
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-07-23 10:23:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 547 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 119,496 KB
最終ジャッジ日時 2023-09-18 04:35:42
合計ジャッジ時間 4,834 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
70,924 KB
testcase_01 AC 75 ms
70,988 KB
testcase_02 AC 71 ms
71,116 KB
testcase_03 AC 69 ms
71,196 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 122 ms
119,496 KB
testcase_09 AC 122 ms
119,252 KB
testcase_10 AC 110 ms
92,432 KB
testcase_11 AC 115 ms
96,760 KB
testcase_12 AC 116 ms
97,608 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 106 ms
106,964 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 69 ms
71,116 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 70 ms
71,228 KB
testcase_29 AC 90 ms
83,212 KB
testcase_30 AC 72 ms
71,240 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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])

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

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

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