結果

問題 No.2018 X-Y-X
ユーザー mkawa2mkawa2
提出日時 2022-07-22 23:11:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,303 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 87,728 KB
最終ジャッジ日時 2023-09-17 12:03:46
合計ジャッジ時間 7,208 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,368 KB
testcase_01 AC 80 ms
71,112 KB
testcase_02 AC 80 ms
71,544 KB
testcase_03 AC 77 ms
71,364 KB
testcase_04 AC 79 ms
71,528 KB
testcase_05 AC 79 ms
71,364 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 106 ms
80,948 KB
testcase_09 AC 108 ms
80,956 KB
testcase_10 AC 101 ms
79,476 KB
testcase_11 AC 102 ms
79,544 KB
testcase_12 AC 104 ms
79,780 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 78 ms
71,116 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 80 ms
71,556 KB
testcase_29 AC 94 ms
77,904 KB
testcase_30 AC 79 ms
71,320 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

from heapq import *

n = II()
s = SI()
t = SI()

if s[0] != t[0] or s[-1] != t[-1]:
    print(-1)
    exit()

aa = [(s[i] != s[i+1])*1 for i in range(n-1)]
bb = [(t[i] != t[i+1])*1 for i in range(n-1)]
# print(aa)
# print(bb)

hp = []
for i in range(n-2):
    if aa[i] == aa[i+1]: heappush(hp, i+1)

ans = 0
for i in range(n-1):
    if aa[i] == bb[i]: continue
    while hp and hp[0] <= i: heappop(hp)
    if len(hp) == 0:
        print(-1)
        exit()
    j = heappop(hp)
    aa[j] ^= 1
    if j+1 < len(aa) and aa[j] == aa[j+1]: heappush(hp, j+1)
    ans += j-i

print(ans)
0