#include #include char clockwork[100]; int len; //Legkisebb egyes csoport max legyen int getFunction_K(int K){ //1. lemásoljuk az arrayt és update k char array[100]; for(int i = 0; i <= len; i++){ array[i] = clockwork[i]; } for(int i = 0; i < len; i++){ if(clockwork[i] == '1'){ array[i+K] = '1'; } } int onemin = 9999; int onecounter = 0; for(int i = 0; i < len; i++){ if(array[i] == '1'){ onecounter++; }else{ if(onecounter < onemin && array[i-1] != '0'){ onemin = onecounter; } onecounter = 0; } } if(onemin == 9999) { return len; } return onemin; } int main(){ scanf("%s",clockwork); len = strlen(clockwork); if(clockwork[0] == '0'){ // opti printf("-1\n"); return 0; } int itercount = 0; while(1){ //printf("%s jelenlegi\n",clockwork); int currmax; int max = 0; int maxk = 0; for(int i = 1; i <= len-1; i++){ currmax = getFunction_K(i); if(currmax > max){ max = currmax; maxk = i; } } //printf("MaxK = %d\n",maxk); char copy[len+1]; int countofone = 0; for(int i = 0; i < len+1;i++){ copy[i] = clockwork[i]; } for(int i = 0; i < len; i++){ if(copy[i] == '1'){ clockwork[i+maxk] = '1'; } if(clockwork[i] == '1')countofone++; } if(itercount == 0 && countofone == len && maxk == 0){ printf("0\n"); break; } itercount++; //printf("countofone: %d\n",countofone); if(countofone == len){ printf("%d\n",itercount); break; } } return 0; }