結果

問題 No.2018 X-Y-X
ユーザー siganai
提出日時 2022-07-22 22:44:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 746 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 98,408 KB
最終ジャッジ日時 2024-07-04 07:16:21
合計ジャッジ時間 4,563 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 6 TLE * 1 -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
from heapq import *
import functools
mod=998244353

import sys
input=sys.stdin.readline

n = int(input())
s = list(input().rstrip())
t = list(input().rstrip())
if s[0] != t[0] or s[-1] != t[-1]:
    print(-1)
    exit()
ans = 0
for i in range(1,n):
    if s[i] != t[i]:
        j = i + 1
        while j < n and s[j-2] != s[j]:
            j += 1
        if j == n:
            print(-1)
            exit()
        for k in range(j-1,i-1,-1):
            if s[k] == 'A':
                s[k] = 'B'
            else:
                s[k] = 'A'
            ans += 1
print(ans)
0