77222024-01-10 18:03:08KristófTakaros Sorozat (80 pont)cpp17Time limit exceeded 8/80500ms4832 KiB
#include <iostream>

using namespace std;

int main()
{
    int n;
    bool ell=false;
    bool ell2=false;
    cin>>n;
    string sor;
    cin>>sor;
    int s[n];
    int s2[n];
    for (int i=0;i<n;i++){
            if(sor[i]=='0'){
        s[i]=0;
            }
            if(sor[i]=='1'){
                s[i]=1;
            }
        s2[i]=s[i];
    }

    bool nulla=false;
    bool end=false;
    int m=0;
    if(s[0]==0){
        m=1;
    }
    int ans=0;
    int ans2=0;
            for(int l=n-1;l>-1;l--){
            if(s[l]!=1){
                ell=true;
            }
            if(ell==true && s[l]==1){
                nulla=false;
                break;
            }
           nulla=true;
        }
        if(nulla==true){
            cout<<0<<endl<<0<<endl;
            return 0;
        }
    while(end==false){
        ell=false;
        
        if(s[0]==0){
        m=1;
    }
    else m=0;
        for(int i=m;i<n-1;i++){
            if(s[i]+s[i+1]==1){
                s[i]=0;
                s[i+1]=0;
                if(m==1){
                    s[i]=1;
                    s[i+1]=1;
                }
                ans++;
                break;
            }

        }
        for(int l=n-1;l>-1;l--){
            if(s[l]!=1){
                ell=true;
            }
            if(ell==true && s[l]==1){
                end=false;
                break;
            }
            end=true;
        }
    }
    cout<<ans<<endl;
    int seged;
bool end2=false;
    int m2=0;
    if(s2[0]==0){
        m2++;
    }
    while(end2==false){
            seged=0;
        if(s2[0]!=0){
        m2=1;
        }
        else m2=0;
        for(int i=m2;i<n-3;i++){
            if(s2[i]+s2[i+1]+s2[i+2]+s2[i+3]==2){
                s2[i]=0;
                s2[i+1]=0;
                s2[i+2]=0;
                s2[i+3]=0;
                if(m2=1){
                    s2[i]=1;
                    s2[i+1]=1;
                    s2[i+2]=1;
                    s2[i+3]=1;
                }
                ans2++;
                seged=1;
                break;
            }
        }
        if(seged==1){
            m2=n;
        }
        for(int i=m2;i<n-1;i++){
            if(s2[i]+s[i+1]==1){
                s2[i]=0;
                s2[i+1]=0;
                if(m2==1){
                    s2[i]=1;
                    s2[i+1]=1;
                }
                ans2++;
                break;
            }

        }
        for(int l=n-1;l>-1;l--){
            if(s2[l]!=1){
                ell2=true;
            }
            if(ell2==true && s2[l]==1){
                end2=false;
                break;
            }
            end2=true;
        }
    }
    cout<<ans2<<endl;



    return 0;
}
SubtaskSumTestVerdictTimeMemory
base8/80
1Time limit exceeded0/0472ms1788 KiB
2Time limit exceeded0/0465ms2312 KiB
3Accepted4/43ms2216 KiB
4Time limit exceeded0/4500ms1712 KiB
5Time limit exceeded0/4453ms2652 KiB
6Time limit exceeded0/4474ms2736 KiB
7Time limit exceeded0/4437ms2220 KiB
8Time limit exceeded0/4465ms3072 KiB
9Time limit exceeded0/4437ms2852 KiB
10Time limit exceeded0/4465ms2976 KiB
11Time limit exceeded0/4476ms3060 KiB
12Time limit exceeded0/4465ms3172 KiB
13Accepted4/44ms4832 KiB
14Time limit exceeded0/4500ms3448 KiB
15Time limit exceeded0/4456ms3672 KiB
16Time limit exceeded0/4460ms3948 KiB
17Time limit exceeded0/4465ms3916 KiB
18Time limit exceeded0/4476ms3924 KiB
19Time limit exceeded0/4469ms3816 KiB
20Time limit exceeded0/4474ms3772 KiB
21Time limit exceeded0/4456ms3948 KiB
22Time limit exceeded0/4460ms3924 KiB