306391: CF1189A. Keanu Reeves

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Keanu Reeves

题意翻译

对于一个01字符串,当它中间0的数量和1的数量不同时,称它为一个好的序列,否则称它为一个不好的序列。 给出一个长度为$n$的01字符串,将它划分为几个字符串,使划分出的几个字符串都是好的序列。 求最少划分出几个字符串,并任意输出一种方案。

题目描述

After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem. Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For example, 1, 101, 0000 are good, while 01, 1001, and 111000 are not good. We are given a string $ s $ of length $ n $ consisting of only zeroes and ones. We need to cut $ s $ into minimal possible number of substrings $ s_1, s_2, \ldots, s_k $ such that all of them are good. More formally, we have to find minimal by number of strings sequence of good strings $ s_1, s_2, \ldots, s_k $ such that their concatenation (joining) equals $ s $ , i.e. $ s_1 + s_2 + \dots + s_k = s $ . For example, cuttings 110010 into 110 and 010 or into 11 and 0010 are valid, as 110, 010, 11, 0010 are all good, and we can't cut 110010 to the smaller number of substrings as 110010 isn't good itself. At the same time, cutting of 110010 into 1100 and 10 isn't valid as both strings aren't good. Also, cutting of 110010 into 1, 1, 0010 isn't valid, as it isn't minimal, even though all $ 3 $ strings are good. Can you help Keanu? We can show that the solution always exists. If there are multiple optimal answers, print any.

输入输出格式

输入格式


The first line of the input contains a single integer $ n $ ( $ 1\le n \le 100 $ ) — the length of the string $ s $ . The second line contains the string $ s $ of length $ n $ consisting only from zeros and ones.

输出格式


In the first line, output a single integer $ k $ ( $ 1\le k $ ) — a minimal number of strings you have cut $ s $ into. In the second line, output $ k $ strings $ s_1, s_2, \ldots, s_k $ separated with spaces. The length of each string has to be positive. Their concatenation has to be equal to $ s $ and all of them have to be good. If there are multiple answers, print any.

输入输出样例

输入样例 #1

1
1

输出样例 #1

1
1

输入样例 #2

2
10

输出样例 #2

2
1 0

输入样例 #3

6
100011

输出样例 #3

2
100 011

说明

In the first example, the string 1 wasn't cut at all. As it is good, the condition is satisfied. In the second example, 1 and 0 both are good. As 10 isn't good, the answer is indeed minimal. In the third example, 100 and 011 both are good. As 100011 isn't good, the answer is indeed minimal.

Input

题意翻译

对于一个01字符串,当它中间0的数量和1的数量不同时,称它为一个好的序列,否则称它为一个不好的序列。 给出一个长度为$n$的01字符串,将它划分为几个字符串,使划分出的几个字符串都是好的序列。 求最少划分出几个字符串,并任意输出一种方案。

加入题单

上一题 下一题 算法标签: