結果

問題 No.2018 X-Y-X
ユーザー siganaisiganai
提出日時 2022-07-22 23:00:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 869 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 86,768 KB
実行使用メモリ 103,016 KB
最終ジャッジ日時 2023-09-17 11:41:49
合計ジャッジ時間 7,749 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
79,064 KB
testcase_01 AC 146 ms
78,928 KB
testcase_02 AC 146 ms
78,576 KB
testcase_03 AC 146 ms
78,572 KB
testcase_04 WA -
testcase_05 AC 145 ms
78,924 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 211 ms
102,616 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 153 ms
80,508 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 150 ms
79,576 KB
testcase_29 AC 153 ms
81,656 KB
testcase_30 AC 153 ms
82,484 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
    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)
            exit()
        li[j] += 1
        ans += j - i
        j += 1
        fl = 1 - fl

    fll[i] = fl
print(ans)
0