21482022-12-25 11:35:10bzsofiaTáblajátékcpp11Accepted 50/503ms3932 KiB
#include <iostream>
#include <deque>

using namespace std;

int i,n,a,j,sor;
deque <int> v;

int main()
{
    cin>>n;
    v.push_back(0);

    for (i=1; i<=n; ++i)
    {
        cin>>a;

        if (a==0)
        {
            v.push_back(0);
            ++sor;
        }
        else if (a==1)
        {
            v.push_back(1);
            ++sor;
        }
        else if (a==2)
        {
            v.pop_back();
            --sor;
        }
        else if (a==3)
        {
            if (v.back()==1) v.back()=0;
            else
            {
                j=v.size()-1;
                while (v[j]==0)
                {
                    v[j]=1;
                    --j;
                }
                v[j]=0;
            }
        }
        else if (a==4)
        {
            if (v.back()==0) v.back()=1;
            else
            {
                j=v.size()-1;
                while (v[j]==1)
                {
                    v[j]=0;
                    --j;
                }
                v[j]=1;
            }
        }
    }

    while (v.size()>1 && v.front()==0) v.pop_front();

    cout<<sor<<"\n";

    for (auto &e:v)
    {
        cout<<e;
    }

    return 0;
}
//6 0 1 4 2 1 0

//6 0 0 0 0 0 0
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/02ms2056 KiB
3Accepted3/32ms2300 KiB
4Accepted3/32ms2452 KiB
5Accepted3/32ms2652 KiB
6Accepted3/32ms2732 KiB
7Accepted3/32ms2872 KiB
8Accepted3/32ms3076 KiB
9Accepted3/32ms3152 KiB
10Accepted3/32ms3280 KiB
11Accepted3/32ms3444 KiB
12Accepted3/32ms3644 KiB
13Accepted4/42ms3768 KiB
14Accepted4/42ms3764 KiB
15Accepted4/42ms3852 KiB
16Accepted4/42ms3924 KiB
17Accepted4/42ms3932 KiB