結果
| 問題 |
No.2018 X-Y-X
|
| コンテスト | |
| ユーザー |
Kiri8128
|
| 提出日時 | 2022-05-04 01:42:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 93 ms / 2,000 ms |
| コード長 | 570 bytes |
| コンパイル時間 | 1,003 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 79,616 KB |
| 最終ジャッジ日時 | 2024-12-23 12:08:31 |
| 合計ジャッジ時間 | 5,160 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
ソースコード
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)
Kiri8128