結果

問題 No.2018 X-Y-X
ユーザー gew1fw
提出日時 2025-06-12 21:44:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 839 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 81,796 KB
実行使用メモリ 82,332 KB
最終ジャッジ日時 2025-06-12 21:49:17
合計ジャッジ時間 3,484 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    S = list(input[idx])
    idx += 1
    T = list(input[idx])
    idx += 1
    
    if S[0] != T[0] or S[-1] != T[-1]:
        print(-1)
        return
    
    delta = [0] * (N)
    for i in range(N):
        if S[i] != T[i]:
            delta[i] = 1
    
    operations = 0
    
    for i in range(N-2):
        j = i + 1
        if delta[j] == 1:
            if S[i] != S[i+2]:
                print(-1)
                return
            # Perform the operation
            S[j] = 'A' if S[j] == 'B' else 'B'
            operations += 1
            delta[j] = 0
    
    for i in range(N):
        if S[i] != T[i]:
            print(-1)
            return
    
    print(operations)

if __name__ == "__main__":
    main()
0