5381: 游戏

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

D. 游戏
每次测试的时间限制
2 秒
每个测试的内存限制
256 兆字节
输入
标准输入
输出
标准输出
瓦夏和彼佳发明了一款新游戏。Vasya 取一条由 1×n 正方形组成的条纹,并将正方形涂成黑色和白色。在那之后,Petya可以开始移动 - 在移动过程中,他可以选择任何两个相邻的方块,并按照他想要的任何方式重新绘制这两个方块,也许是不同的颜色。彼佳只能用白色和黑色重新粉刷方块。Petya的目标是重新粉刷条纹,这样就不会有两个相邻的正方形是一种颜色。帮助Petya,使用给定的初始颜色,找到Petya获胜所需的最小移动次数。
输入
第一行包含数字 n (1≤n≤1000),表示条带的长度。第二行正好包含 n 个符号 - 线条的初始颜色。0 对应于白色方块,1 对应于黑色方块。
输出
如果 Petya 无法以这样的初始着色获胜,请打印 -1。否则,打印Petya获胜所需的最小移动次数。
例子
输入
6
111010
输出
1
输入
5
10001
输出
1
输入
7
1100010
输出
2
输入
5
00100
输出
2
注意
在第一个样本中,Petya 可以取正方形 1 和 2。他将正方形 1 重新绘制为黑色,将正方形 2 重新绘制为白色。
在第二个样本中,Petya 可以取正方形 2 和 3。他将正方形 2 重新绘制为白色,将正方形 3 重新绘制为黑色。
D. Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya and Petya have invented a new game. Vasya takes a stripe consisting of n square and paints the squares black and white. After that Petya can start moves − during a move he may choose any two neighboring squares of one color and repaint these two squares any way he wants, perhaps in different colors. Petya can only repaint the squares in white and black colors. Petya’s aim is to repaint the stripe so that no two neighboring squares were of one color. Help Petya, using the given initial coloring, find the minimum number of moves Petya needs to win.
Input
The first line contains number n (1≤n≤1000) which represents the stripe’s length. The second line contains exactly n symbols − the line’s initial coloring. 0 corresponds to a white square, 1 corresponds to a black one.
Output
If Petya cannot win with such an initial coloring, print -1. Otherwise print the minimum number of moves Petya needs to win.
Examples
Input
6
111010
Output
1
Input
5
10001
Output
1
Input
7
1100010
Output
2
Input
5
00100
Output
2
Note
In the first sample Petya can take squares 1 and 2. He repaints square 1 to black and square 2 to white.
In the second sample Petya can take squares 2 and 3. He repaints square 2 to white and square 3 to black.

输入样例 复制


输出样例 复制