結果

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

ソースコード

diff #

n = int(input())
s = list(input())
t = list(input())

diff_positions = []
for i in range(n):
    if s[i] != t[i]:
        diff_positions.append(i)

count = 0
possible = True

for i in diff_positions:
    if i < 1 or i >= n-1:
        possible = False
        break
    if s[i-1] != s[i+1]:
        possible = False
        break
    # Perform the operation
    s[i] = 'B' if s[i] == 'A' else 'A'
    count += 1

if possible and s == t:
    print(count)
else:
    print(-1)
0