8222022-01-18 10:56:51zsebiTáblajátékcpp11Accepted 50/502ms1904 KiB
#include <iostream>
//#include <fstream>
#include <algorithm>
#include <vector>
#include <deque>

using namespace std;

//ifstream cin ("tabla.in");
//ofstream cout ("tabla.out");

deque < int > x;
deque <int> y;
int n,sor,i,j,a,p;

int main()
{
    cin>>n;
    sor=0;
    for(i=1;i<=n;++i)
    {
        cin>>a;
        if(a==0)
        {
            sor++;
            x.push_back(0);
        }
        else if(a==1)
        {
            sor++;
            x.push_back(1);
        }
        else if(a==2)
        {
            sor--;
            x.pop_back();
        }
        else if(a==4)
        {
            for(j=x.size()-1;j>=0;--j)
            {
                if(x[j]==0)
                {
                    x[j]=1;
                for(p=j+1;p<x.size();++p)x[p]=0;
                break;
                }
            }
        }
        else if(a==3)
        {
            for(j=x.size()-1;j>=0;--j)
            {
                if(x[j]==1)
                {
                    x[j]=0;
                for(p=j+1;p<x.size();++p)x[p]=1;
                break;

                }
            }
        }
    }

    while(!x.empty() && x.front()==0) x.pop_front();

    if(x.empty()) x.push_back(0);

    cout<<sor<<"\n";
    for(i=0;i<x.size();++i)
        cout<<x[i];
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms1744 KiB
2Accepted0/01ms1780 KiB
3Accepted3/31ms1852 KiB
4Accepted3/31ms1852 KiB
5Accepted3/31ms1852 KiB
6Accepted3/31ms1852 KiB
7Accepted3/31ms1864 KiB
8Accepted3/31ms1864 KiB
9Accepted3/31ms1868 KiB
10Accepted3/31ms1880 KiB
11Accepted3/31ms1880 KiB
12Accepted3/32ms1884 KiB
13Accepted4/41ms1892 KiB
14Accepted4/41ms1888 KiB
15Accepted4/41ms1896 KiB
16Accepted4/42ms1896 KiB
17Accepted4/41ms1904 KiB