AtCoder Regular Contest 109
F
1D Kingdom Builder
AtCoder
⌀ 3625
原题
← E→
翻译中…

Problem Statement

翻译中…

Snuke is playing with a board composed of infinitely many squares lining up in a row. Each square has an assigned integer; for each integer $i$, Square $i$ and Square $i+1$ are adjacent. Additionally, each square is painted white or black.

翻译中…

A string $s$ of length $n$ consisting of w and b represents the colors of the squares of this board, as follows:

翻译中…
  • For each $i = 1, 2, \dots, n$, Square $i$ is white if the $i$-th character of $s$ is w, and black if that character is b;
  • For each $i \leq 0$, Square $i$ is white;
  • For each $i > n$, Square $i$ is black.
翻译中…

Snuke has infinitely many white pieces and infinitely many black pieces. He will put these pieces on the board as follows:

翻译中…
  • (1) Choose a piece of the color of his choice.
  • (2) Among the squares adjacent to a square that already contains a piece, look for squares of the same color as the chosen piece.
  • (2a) If there are such squares, choose one of them and put the piece on it;
    • (2b) if there is no such square, choose a square of the same color as the chosen piece and put the piece on it.
翻译中…

The board initially has no piece on it.

翻译中…

You are given a string $t$ of length $n$ consisting of o and _. Find the minimum number of pieces Snuke needs to put on the board to have a piece on every square $i$ among Squares $1,..,n$ such that the $i$-th character of $t$ is o. It is guaranteed that $t$ has at least one occurrence of o.

翻译中…

Constraints

翻译中…
  • $1 \leq n \leq 10^5$
  • $|s| = |t| = n$
  • $s$ consists of w and b.
  • $t$ consists of o and _.
  • $t$ has at least one occurrence of o.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

n
s
t

翻译中…

Output

翻译中…

Print the minimum number of pieces Snuke needs to put on the board.

翻译中…

样例

Input #1
3
wbb
o_o
Output #1
2
Let us use `W` to represent a white square that needs a piece on it, `B` to represent a black square that needs a piece on it, `w` to represent a white square that does not need a piece on it, and `b` to represent a black square that does not need a piece on it. We have the following board: If we put pieces in the following order, two pieces is enough: Note that if we put a piece on the white square first, we will need three or more pieces:
Input #2
4
wwww
o__o
Output #2
3
If we put pieces in the following order, three pieces is enough:
Input #3
9
bbwbwbwbb
_o_o_o_o_
Output #3
5
If we put pieces in the following order, five pieces is enough:
Input #4
17
wwwwbbbbbbbbwwwwb
__o__o_o_ooo__oo_
Output #4
11
题目信息
题号
arc109_f
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。