1189A - Keanu Reeves - CodeForces Solution


strings *800

Please click on ads to support us..

Python Code:


n = input()
s = input()
count_1 = 0
count_0 = 0
for i in s:
    if i == "1":
        count_1 += 1
    else:
        count_0 += 1

if count_1 == count_0:
    print(2)
    print(s[0] + " " + s[1:])
else:
    print(1)
    print(s)


C++ Code:

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 110;

bool dp[MAXN][MAXN];
int last[MAXN][MAXN];
int s[MAXN];
char c[MAXN];

void printans(int k, int n){
    if(n == 0) return;
    int j = last[k][n];
    printans(k - 1, j - 1);
    for(int i = j; i <= n; i++){
        printf("%d", s[i]);
    }
    printf(" ");
}

int main(){
    int n; scanf("%d", &n);
    scanf(" %s", c);
    for(int i = 0; i < n; i++){
        s[i + 1] = c[i] - '0';
    }

    for(int i = 0; i <= n; i++) dp[i][i] = true;

    for(int i = 1; i <= n; i++){
        for(int k = 1; k <= i; k++){
            int qtd0 = 0, qtd1 = 0;
            for(int j = i; j >= 1; j--){
                if(s[j] == 0) qtd0++;
                if(s[j] == 1) qtd1++;
                if(qtd0 == qtd1) continue;
                if(dp[k - 1][j - 1]){
                    dp[k][i] = true;
                    last[k][i] = j;
                    break;
                }
            }
        }
    }

    for(int k = 1; k <= n; k++){
        if(dp[k][n]){
            printf("%d\n", k);
            printans(k, n);
            return 0;
        }
    }
}
 	  	  			 	 	    	   	  	  			


Comments

Submit
0 Comments
More Questions

1684C - Column Swapping
57C - Array
1713D - Tournament Countdown
33A - What is for dinner
810A - Straight A
1433C - Dominant Piranha
633A - Ebony and Ivory
1196A - Three Piles of Candies
299A - Ksusha and Array
448B - Suffix Structures
1092B - Teams Forming
1166C - A Tale of Two Lands
544B - Sea and Islands
152B - Steps
1174D - Ehab and the Expected XOR Problem
1511A - Review Site
1316A - Grade Allocation
838A - Binary Blocks
1515D - Phoenix and Socks
1624D - Palindromes Coloring
1552F - Telepanting
1692G - 2Sort
1191A - Tokitsukaze and Enhancement
903A - Hungry Student Problem
52B - Right Triangles
1712A - Wonderful Permutation
1712D - Empty Graph
1712B - Woeful Permutation
1712C - Sort Zero
1028B - Unnatural Conditions