Advertisement
ekzolot

Untitled

Apr 15th, 2022
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. bool checking(int a, string seq){
  5.     string s;
  6.     for (int i=0; i<a; i++){
  7.         if(i%2==0){
  8.             s+="0";
  9.         }else{
  10.             s+="1";
  11.         }
  12.     }
  13.     int n=seq.length();
  14.     int j=0;
  15.     for (int i=0; i<a; i++){
  16.         if(s[i]==seq[j]){
  17.             j++;
  18.             if (j==n){
  19.                 return true;
  20.             }
  21.         }
  22.     }
  23.     return false;
  24. }
  25. int main(){
  26.     string seq;
  27.     cin>>seq;
  28.     int l=0;
  29.     int r=1000000;
  30.     while (r-l>1){
  31.         int m=(l+r)/2;
  32.         if (checking(m, seq)){
  33.             r=m;
  34.         }
  35.         else{
  36.             l=m;
  37.         }
  38.     }
  39.     cout<<r<<endl;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement