結果

問題 No.2018 X-Y-X
ユーザー siganaisiganai
提出日時 2022-07-22 23:10:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 909 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 86,860 KB
実行使用メモリ 102,956 KB
最終ジャッジ日時 2023-09-17 12:00:37
合計ジャッジ時間 7,914 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 153 ms
78,888 KB
testcase_01 AC 147 ms
79,012 KB
testcase_02 AC 149 ms
78,596 KB
testcase_03 AC 142 ms
78,896 KB
testcase_04 AC 148 ms
78,804 KB
testcase_05 AC 148 ms
79,068 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 208 ms
102,844 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 151 ms
80,624 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 151 ms
79,300 KB
testcase_29 AC 158 ms
82,004 KB
testcase_30 AC 152 ms
82,528 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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
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)
0