13562022-05-22 15:33:59nkdorka1212Táblajátékcpp11Accepted 50/502ms1944 KiB
#include <bits/stdc++.h>

using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int>sor(n+1,0);
    vector<int>oszlop;
    oszlop.push_back(1);
    int s=0;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        if(a==0)
        {
            s++;
            oszlop.push_back(0);
        }else if(a==1)
        {
            s++;
            oszlop.push_back(1);
        }else if(a==2)
        {
            s--;
            oszlop.pop_back();
        }else if((a==3 && oszlop[s]==0) || (a==4 && oszlop[s]==1))
        {
            int valt=oszlop[s];
            int k=s;
            while(oszlop[k]==valt)
            {
                oszlop[k]=1-valt;
                k--;
            }
            oszlop[k]=valt;
        }else
        {
            oszlop[s]=1-oszlop[s];
        }

    }
    cout<<s<<"\n";
    bool ok=false;
    for(int i=1;i<=s;i++)
    {
        if(oszlop[i]==1)
        {
            ok=true;
        }
        if(ok)
        {
            cout<<oszlop[i];
        }
    }
    if(!ok)
    {
        cout<<0;
    }
    cout<<"\n";

    return 0;
}

/*
6
0 1 4 2 1 0

*/
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1820 KiB
2Accepted0/01ms1812 KiB
3Accepted3/31ms1864 KiB
4Accepted3/31ms1864 KiB
5Accepted3/31ms1864 KiB
6Accepted3/31ms1868 KiB
7Accepted3/31ms1876 KiB
8Accepted3/31ms1880 KiB
9Accepted3/31ms1880 KiB
10Accepted3/31ms1892 KiB
11Accepted3/31ms1888 KiB
12Accepted3/31ms1896 KiB
13Accepted4/41ms1900 KiB
14Accepted4/41ms1904 KiB
15Accepted4/41ms1904 KiB
16Accepted4/41ms1920 KiB
17Accepted4/41ms1944 KiB