Codeforces Round #572 (Div. 2) Keanu Reeves

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 s1,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,…,sk such that their concatenation (joining) equals s, i.e. s1+s2+⋯+sk=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.

Input
The first line of the input contains a single integer n (1≤n≤100) — the length of the string s.

The second line contains the string s of length n consisting only from zeros and ones.

Output
In the first line, output a single integer k (1≤k) — a minimal number of strings you have cut s into.

In the second line, output k strings s1,s2,…,sk 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.

Examples
input

1
1
output
1
1
input
2
10
output
2
1 0
input
6
100011
output
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.

题意理解:
需要注意答案并不唯一,第三组的一个可行解为1 00011
读懂了就不难解决了
还有就是输出上可以下点功夫

#include<iostream>
using namespace std;
int main()
{
    string a;
    long long n,ans=0;
    cin>>n>>a;
    for(long long i=0;i<n;i++)
    {
        if(a[i]=='0')
            ans++;
    }
    if(ans*2==n)
    {
        cout<<2<<endl;
        cout<<a[0];
        a[0]=' ';
        cout<<a<<endl;
    }
    else
    {
        cout<<"1"<<endl;
        cout<<a<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值