77182024-01-10 17:17:43KristófTakaros Sorozat (80 pont)cpp17Wrong answer 8/806ms6116 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;
            }
    else 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;
bool end2=false;
    int m2=0;
    if(s2[0]==0){
        m2++;
    }
    while(end2==false){
        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++;
                break;
            }
        }
        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
1Wrong answer0/03ms1684 KiB
2Wrong answer0/06ms3780 KiB
3Accepted4/43ms2208 KiB
4Wrong answer0/43ms2152 KiB
5Wrong answer0/43ms2340 KiB
6Wrong answer0/43ms2588 KiB
7Wrong answer0/43ms2768 KiB
8Wrong answer0/43ms2832 KiB
9Wrong answer0/43ms2948 KiB
10Wrong answer0/43ms2960 KiB
11Wrong answer0/43ms3072 KiB
12Wrong answer0/43ms3176 KiB
13Accepted4/46ms5124 KiB
14Wrong answer0/46ms5272 KiB
15Wrong answer0/46ms5208 KiB
16Wrong answer0/46ms5468 KiB
17Wrong answer0/46ms5820 KiB
18Wrong answer0/46ms5632 KiB
19Wrong answer0/44ms5860 KiB
20Wrong answer0/46ms6116 KiB
21Wrong answer0/46ms6044 KiB
22Wrong answer0/46ms6068 KiB