8192022-01-17 12:40:34kicsiboglarTáblajátékcpp11Accepted 50/502ms1904 KiB
#include <iostream>
#include <deque>
#define ll long long 

using namespace std;

ll n, i, a, s, osz;
deque < ll> o;

/*void bin(ll m)
{
    ll x[501], db = 0;
    while (m > 0)
    {
        x[db] = m % 2;
        m /= 2;
        db++;
    }
    if (db == 0) cout << "0";
    else for (i = db-1; i >= 0; --i) cout << x[i];
}*/

void binary(int m)
{
    if (m < 2)
    {
        cout << m;
    }
    else
    {
        deque <int> x;
        while (m >= 1)
        {
            x.push_front(m % 2);
            m = m / 2;
        }
        for (auto e : x) cout << e;
    }
    /*if ((m / 2) > 0) binary(m / 2);
    cout << m % 2;*/
}
int main()
{
    cin >> n;
    s = 0;
    o.push_back(0);
    for (i = 1; i <= n; ++i)
    {
        cin >> a;
        if (a <= 1)
        {
            s++;
            o.push_back(a);
            osz = (osz * 2) + a;
        }
        else if (a == 2)
        {
            s--;
            o.pop_back();
            osz /= 2;
        }
        else if (a == 3)
        {
            if (o.back() == 1) o.back() = 0;
            else
            {
                ll j = o.size() - 1;
                while (j >= 0)
                {
                    if (o[j] == 0) o[j] = 1;
                    else
                    {
                        o[j] = 0;
                        break;
                    }
                    --j;
                }
            }
        }
        else
        {
            if (o.back() == 0) o.back() = 1;
            else
            {
                ll j = o.size() - 1;
                if (o[0] == 1) o.push_front(0);
                while (j >= 0)
                {
                    if (o[j] == 1) o[j] = 0;
                    else
                    {
                        o[j] = 1;
                        break;
                    }
                    --j;
                }
            }
        }
    }
    cout << s << "\n";
    if (o.size() == 1) cout << o[0];
    else
    {
        while (o.size()!=1 && o[0] == 0) o.pop_front();
        for (auto e : o) cout << e;
        cout << "\n";
    }
    return 0;
}


SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1744 KiB
2Accepted0/01ms1800 KiB
3Accepted3/31ms1840 KiB
4Accepted3/31ms1848 KiB
5Accepted3/31ms1852 KiB
6Accepted3/31ms1856 KiB
7Accepted3/31ms1864 KiB
8Accepted3/31ms1864 KiB
9Accepted3/31ms1864 KiB
10Accepted3/31ms1872 KiB
11Accepted3/31ms1876 KiB
12Accepted3/31ms1884 KiB
13Accepted4/41ms1880 KiB
14Accepted4/41ms1888 KiB
15Accepted4/41ms1888 KiB
16Accepted4/42ms1896 KiB
17Accepted4/41ms1904 KiB