結果

問題 No.2018 X-Y-X
ユーザー Kiri8128Kiri8128
提出日時 2022-05-04 01:42:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 80,516 KB
最終ジャッジ日時 2023-08-25 00:27:08
合計ジャッジ時間 5,014 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,088 KB
testcase_01 AC 77 ms
71,208 KB
testcase_02 AC 75 ms
71,172 KB
testcase_03 AC 75 ms
71,284 KB
testcase_04 AC 76 ms
71,132 KB
testcase_05 AC 76 ms
71,112 KB
testcase_06 AC 103 ms
80,504 KB
testcase_07 AC 107 ms
80,284 KB
testcase_08 AC 99 ms
80,424 KB
testcase_09 AC 99 ms
80,416 KB
testcase_10 AC 94 ms
77,952 KB
testcase_11 AC 98 ms
78,764 KB
testcase_12 AC 100 ms
79,644 KB
testcase_13 AC 101 ms
80,160 KB
testcase_14 AC 100 ms
79,848 KB
testcase_15 AC 112 ms
80,516 KB
testcase_16 AC 104 ms
79,196 KB
testcase_17 AC 101 ms
80,268 KB
testcase_18 AC 94 ms
77,600 KB
testcase_19 AC 110 ms
80,408 KB
testcase_20 AC 105 ms
80,376 KB
testcase_21 AC 96 ms
79,936 KB
testcase_22 AC 101 ms
79,784 KB
testcase_23 AC 80 ms
76,132 KB
testcase_24 AC 101 ms
80,428 KB
testcase_25 AC 106 ms
80,312 KB
testcase_26 AC 102 ms
79,916 KB
testcase_27 AC 95 ms
77,300 KB
testcase_28 AC 79 ms
75,636 KB
testcase_29 AC 84 ms
76,704 KB
testcase_30 AC 83 ms
77,204 KB
testcase_31 AC 98 ms
78,596 KB
testcase_32 AC 102 ms
79,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = [ord(a) - 65 for a in input()]
T = [ord(a) - 65 for a in input()]
if S[0] != T[0] or S[-1] != T[-1]:
    print(-1)
    exit()

before, flip, ans = 0, 0, 0
for i in range(N - 1):
    xor = S[i] ^ T[i]
    next_xor = S[i+1] ^ T[i+1]
    r_before = before ^ xor ^ (flip & 1) ^ (S[i-1] ^ S[i+1]) if flip else 0
    next_flip = max(0, flip + r_before - 1)
    if (next_flip ^ next_xor) % 2:
        next_flip += 1

    before = r_before ^ 1 if flip and next_flip else 0
    flip = next_flip
    ans += flip

print(-1 if flip else ans)
0