結果
問題 |
No.2018 X-Y-X
|
ユーザー |
![]() |
提出日時 | 2022-07-22 23:10:18 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 909 bytes |
コンパイル時間 | 172 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 94,532 KB |
最終ジャッジ日時 | 2024-07-04 07:51:40 |
合計ジャッジ時間 | 4,661 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 WA * 22 |
ソースコード
#!/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 fl = 0 j = 0 li = [0] * n fll = [0] * n for i in range(1,n-1): if li[i]: fl = 1 - fl fll[i] = fl if (fl == 0 and s[i] != t[i]) or (fl == 1 and s[i] == t[i]): j = max(j,i + 1) while j < n and ((fll[j-2] == 0 and s[j-2] != s[j]) or (fll[j-2] == 1 and s[j-2] == s[j])): j += 1 if j == n: print(-1) break li[j] += 1 ans += j - i j += 1 fl = 1 - fl #print(fl,i) fll[i] = fl else: print(ans)