CF1189A.Keanu Reeves

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ss of length nn consisting of only zeroes and ones. We need to cut ss into minimal possible number of substrings s1,s2,…,sks_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 s1,s2,…,sks_1, s_2, \ldots, s_k such that their concatenation (joining) equals ss, i.e. s1+s2+⋯+sk=ss_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 33 strings are good.

Can you help Keanu? We can show that the solution always exists. If there are multiple optimal answers, print any.

在经典电影《黑客帝国》三部曲中饰演尼奥之后,基努·里维斯开始怀疑自己:我们是否真的生活在虚拟现实中?为了验证这一点,他需要解决如下问题。

我们称一个仅由 0 和 1 组成的字符串为好字符串,当且仅当其中 0 的个数与 1 的个数不相等。例如,1、101、0000 是好字符串,而 01、1001 和 111000 不是好字符串。

现给定一个长度为 nn 的字符串 ss,它仅由 0 和 1 组成。我们需要将 ss 切分为尽可能少的子串 s1,s2,…,sks_1, s_2, \ldots, s_k,使得每个子串都是好字符串。更准确地说,我们要找到一个由好字符串构成的序列 s1,s2,…,sks_1, s_2, \ldots, s_k,使其连接(拼接)后等于 ss,即 s1+s2+⋯+sk=ss_1 + s_2 + \dots + s_k = s,且 kk 尽可能小。

例如,将 110010 切分为 110 和 010,或切分为 11 和 0010,都是合法的,因为 110、010、11、0010 均为好字符串;而 110010 本身不是好字符串,因此无法只切分为 1 段,故上述两种方案已达到最小段数。另一方面,将 110010 切分为 1100 和 10 是非法的,因为这两个子串均非好字符串。此外,将 110010 切分为 1、1、0010 也是非法的——尽管这三段均为好字符串,但该方案并非段数最少的方案。

你能帮帮基努吗?可以证明该问题总有解。若存在多个最优解,输出任意一个即可。

输入格式

The first line of the input contains a single integer nn (1≤n≤1001\le n \le 100) — the length of the string ss.

The second line contains the string ss of length nn consisting only from zeros and ones.

输入的第一行包含一个整数 nn(1≤n≤1001\le n \le 100)——字符串 ss 的长度。

第二行包含一个长度为 nn 的字符串 ss,该字符串仅由 0 和 1 组成。

输出格式

In the first line, output a single integer kk (1≤k1\le k) — a minimal number of strings you have cut ss into.

In the second line, output kk strings s1,s2,…,sks_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 ss and all of them have to be good.

If there are multiple answers, print any.

在第一行,输出一个整数 kk(1≤k1\le k)—— 将字符串 ss 切分为若干子串的最少数量。

在第二行,输出 kk 个字符串 s1,s2,…,sks_1, s_2, \ldots, s_k,以空格分隔。每个字符串的长度必须为正;它们的拼接结果必须等于 ss,且每个字符串都必须是“好”的。

若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#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.

在第一个例子中,字符串 1 完全未被切割。由于它本身是“好”的,因此满足条件。

在第二个例子中,1 和 0 均为“好”的。由于 10 不是“好”的,因此该答案确实是最小的。

在第三个例子中,100 和 011 均为“好”的。由于 100011 不是“好”的,因此该答案确实是最小的。

输入解题思路,AI测评打分。不知道怎么写?

首页