73022024-01-06 15:36:10KristófÉrdekes túra (70 pont)cpp17Time limit exceeded 1/70500ms4224 KiB
#include <iostream>

using namespace std;

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

    bool end=false;
    int m=0;
    if(s[0]==0){
        m=1;
    }
    int ans=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++;
    }
    int ans2=0;
    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
base1/70
1Time limit exceeded0/0444ms2000 KiB
2Time limit exceeded0/0465ms2128 KiB
3Time limit exceeded0/3462ms1888 KiB
4Partially correct1/33ms2756 KiB
5Time limit exceeded0/3500ms2116 KiB
6Time limit exceeded0/3446ms2396 KiB
7Time limit exceeded0/3453ms3240 KiB
8Time limit exceeded0/3456ms3364 KiB
9Time limit exceeded0/3465ms3468 KiB
10Time limit exceeded0/3465ms3620 KiB
11Time limit exceeded0/3469ms2852 KiB
12Time limit exceeded0/3453ms2928 KiB
13Time limit exceeded0/4444ms2820 KiB
14Time limit exceeded0/4465ms3256 KiB
15Time limit exceeded0/4481ms3260 KiB
16Time limit exceeded0/4462ms3732 KiB
17Time limit exceeded0/4458ms3588 KiB
18Time limit exceeded0/4460ms3852 KiB
19Time limit exceeded0/4477ms4064 KiB
20Time limit exceeded0/4449ms4224 KiB
21Time limit exceeded0/4465ms4220 KiB
22Time limit exceeded0/4460ms4216 KiB