結果

問題 No.2018 X-Y-X
ユーザー Kiri8128Kiri8128
提出日時 2022-05-03 23:24:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 708 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 86,908 KB
実行使用メモリ 80,792 KB
最終ジャッジ日時 2023-09-16 19:58:48
合計ジャッジ時間 4,624 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,100 KB
testcase_01 AC 67 ms
71,316 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 67 ms
71,192 KB
testcase_05 AC 69 ms
71,332 KB
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 105 ms
80,564 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 89 ms
77,172 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 91 ms
76,524 KB
testcase_29 AC 78 ms
76,692 KB
testcase_30 AC 95 ms
78,560 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = [ord(a) - 65 for a in input()]
T = [ord(a) - 65 for a in input()]
inf = 10 ** 9
null, m, lm, rm, lrm, mlrm = 0, inf, inf, inf, inf, inf

for i in range(1, N - 1):
    nnull, nm, nlm, nrm, nlrm, nmlrm = inf, inf, inf, inf, inf, inf
    if S[i] == T[i]:
        nnull = min(null, m, lm)
        if S[i-1] == S[i+1]:
            nmlrm = min(rm, lrm) + 2
    else:
        if S[i-1] == S[i+1]:
            nm = min(null, rm, lrm) + 1
            nlrm = min(m, lm, mlrm) + 1
        else:
            nlm = min(m, lm, mlrm) + 1
            nrm = min(null, rm, lrm) + 1
    null, m, lm, rm, lrm, mlrm = nnull, nm, nlm, nrm, nlrm, nmlrm

ans = min((null, m, lm))
print(ans if ans < inf else -1)
0