P26381 [AtCoder] Sushi Tower
提高-
题目描述

Problem Description

Sushi is a food where "shari" (sushi rice) is topped with " neta" (sushi topping).

Ringo is trying to create a sushi tower by stacking $ N $ pieces of sushi. Having $ N $ pieces of sushi means having $ N $ pieces of shari and $ N $ pieces of neta, totaling $ 2N $ parts. Ringo wants to stack these parts in a certain order.

There are three ways to stack one piece of sushi:

  • Stack as is: shari, neta in that order.
  • Flip and stack: neta, shari in that order.
  • Disassemble and stack: Disassemble the sushi into shari and neta and stack them separately.

For example, if you want to stack 3 pieces of sushi in the order "neta, shari, neta, neta, shari, shari" from the bottom up, you can stack them as follows:

  1. Disassemble one piece of sushi and stack the neta. Keep the shari for later.
  2. Stack a piece of sushi as is.
  3. Flip and stack a piece of sushi.
  4. Stack the shari that was kept aside.

Since disassembling sushi is time-consuming, Ringo wants to minimize the number of sushi pieces that need to be disassembled. Find the minimum number of sushi pieces that need to be disassembled to create the desired sushi tower.

Input Format

The input is given from the standard input in the following format:

$ N $ $ S $

  • The first line contains an integer $N\ (1\ ≦\ N\ ≦\ 256)$ representing the number of pieces of sushi.
  • The second line contains a string $ S $ of length $ 2N $ representing the order in which parts should be stacked. $ S $ is a string consisting of $ N $ 0s and $ N $ 1s. When the $i\ (1≦i≦2N)$th character of $ S $ is 0, it means that shari should be stacked at the $ i $th position from the bottom. When it is 1, it means that neta should be stacked at the $ i $th position from the bottom.

Output Format

Output the minimum number of sushi pieces that need to be disassembled to create the desired sushi tower. End the output with a newline.

Sample Input and Output

Sample Input #1

3
101100

Sample Output #1

1

Sample Input #2

5
0000111011

Sample Output #2

3

Notes/Hints

Sample Explanation 1

This is as described in the problem statement. The figure below shows an example of how to stack, where white circles represent shari and red rectangles represent neta. figure1

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 101100
样例输出
1