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.
玩完黑客帝国传奇三部曲之后,基努·里维斯(主角演员)开始怀疑人生:我们是不是真的活在VR当中?为了探究这是不是真的,他得去解决如下的问题。
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, 0000are good, while 01, 1001, and 111000 are not good.
我们认为一个只含有0和1,并且0和1数目不同的一个字符串是个好字符串。比如说,1,101,0000都是好字符串,但是01,1001,和111000都不是好字符串。
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,…,sks1,s2,…,sk such that all of them are good. More formally, we have to find minimal by number of strings sequence of good strings s1,s2,…,sks1,s2,…,sk such that their concatenation (joining) equals ss, i.e. s1+s2+⋯+sk=ss1+s2+⋯+sk=s.
我们给定了一个字符串s,长度为n,这里边仅仅包含0和1。我们得用尽量小的分段数把原字符串分成“好的”子字符串。更正式的说,我们得去找一个以最小数目切分字符串,并且各个子字符串最终得拼成原字符串(就是只能直接分段,不能逐项挑)。
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.
比如说,切110010为110和010或者切成11和0010都是合理的。 但是没法把110010切成更小部分(一段就是不切),因为110010本身不符合题意。也没法把它切成不好的字符串。
Can you help Keanu? We can show that the solution always exists. If there are multiple optimal answers, print any.
你能帮助基努吗,我们可以认定解是一定存在的。如果有多解,任意输出即可。
Input
The first line of the input contains a single integer nn (1≤n≤1001≤n≤100) — the length of the string ss.
第一行输入包含一个整数
The second line contains the string ss of length nn consisting only from zeros and ones.
第二行包含一个01字符串
Output
In the first line, output a single integer kk (1≤k1≤k) — a minimal number of strings you have cut ss into.
In the second line, output kk strings s1,s2,…,sks1,s2,…,sk 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.
Examples
input
Copy
1
1
output
Copy
1
1
input
Copy
2
10
output
Copy
2
1 0
input
Copy
6
100011
output
Copy
2
100 011
Note
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.
这个题的核心就是一个IDEA:对于相等的01个数总是可以通过移出任意一个0或1使得刚才的稳定对数被打破。
那么,这个题只需两个思路方向:
- 已输入的字符串01不能一一匹配,直接就是答案
- 输入的字符串可以一一匹配,拆出最后一个数即可满足题给条件。这时段数总是2。
思路简述如上。
//#include<pch.h>
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <cstring>
#include <cmath>
#define DETERMINATION main
#define lldin(a) scanf("%lld", &a)
#define println(a) printf("%lld\n", a)
#define reset(a, b) memset(a, b, sizeof(a))
const int INF = 0x3f3f3f3f;
using namespace std;
const double PI = acos(-1);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int mod = 1000000007;
const int tool_const = 19991126;
const int tool_const2 = 33;
inline ll lldcin()
{
ll tmp = 0, si = 1;
char c;
c = getchar();
while (c > '9' || c < '0')
{
if (c == '-')
si = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
{
tmp = tmp * 10 + c - '0';
c = getchar();
}
return si * tmp;
}
///Untersee Boot IXD2(1942)
/**Although there will be many obstructs ahead,
the desire for victory still fills you with determination..**/
/**Last Remote**/
string tmp;
int DETERMINATION()
{
ios::sync_with_stdio(false);
ll n;
cin >> n;
cin >> tmp;
ll cnt0 = 0, cnt1 = 0;
for (char i : tmp)//判断0与1的个数
{
if (i == '0')
cnt0++;
else
cnt1++;
}
if (cnt1 != cnt0)//情况1
{
cout << 1 << endl << tmp << endl;
}
else//情况2
{
cout << 2 << endl;
for (int i = 0; i < n - 1; i++)
cout << tmp[i];
cout << " " << tmp[n - 1] << endl;
}
return 0;
}