28912023-02-02 09:31:05tamasmarkTáblajátékcpp17Accepted 50/503ms3920 KiB
// tablajatek.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <deque>

using namespace std;

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

int main()
{
    cin >> n;
    x.push_back(0);
    for (i = 1; i<=n; ++i)
    {
        cin >> a;
        if (a == 0)
        {
            sor++;
            //hely = hely * 2;
            x.push_back(0);
        }
        else if (a == 1)
        {
            sor++;
            //hely = (hely * 2) + 1;
            x.push_back(1);

        }
        else if (a == 2)
        {
            sor--;
            /*if (hely % 2 == 0)
            {
                hely = hely / 2;
            }
            else if (hely % 2 != 0)
            {
                hely = hely - 1;
                hely = hely / 2;
            }*/
            x.pop_back();
        }
        else if (a == 3)
        {
            //hely--;
            if (x.back() == 1) x.back()=0;
            else
            {
                j = x.size() - 1;
                while (x[j] == 0)
                {
                    x[j] = 1;
                    j--;
                }
            x[j] = 0;
            }
            
        }
        else if (a == 4)
        {
            //hely++;
            if (x.back() == 0) x.back()=1;
            else
            {
                j = x.size() - 1;
                while (x[j] == 1)
                {
                    x[j] = 0;
                    j--;
                }
                x[j] = 1;
            }
        }
    }
    while (x.size() > 1 && x.front() == 0) x.pop_front();
    /*while (hely / 2)
    {
        if (hely % 2==0)
        {
            x.push_front(0);
        }
        else
        {
            x.push_front(1);
        }
        hely = hely / 2;
    }
    if (hely % 2 == 0) x.push_front(0);
    else x.push_front(1);*/
    cout << sor << "\n";
    for (i = 0; i < x.size(); ++i)
    {
        cout << x[i];
    }
    return 0;
}
/*
6 
0 1 4 2 1 0
6 
0 0 0 0 0 0
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1816 KiB
2Accepted0/03ms2000 KiB
3Accepted3/33ms2216 KiB
4Accepted3/33ms2300 KiB
5Accepted3/32ms2428 KiB
6Accepted3/33ms2816 KiB
7Accepted3/33ms2860 KiB
8Accepted3/32ms2940 KiB
9Accepted3/32ms3072 KiB
10Accepted3/33ms3312 KiB
11Accepted3/32ms3312 KiB
12Accepted3/32ms3304 KiB
13Accepted4/43ms3432 KiB
14Accepted4/43ms3664 KiB
15Accepted4/43ms3720 KiB
16Accepted4/43ms3828 KiB
17Accepted4/43ms3920 KiB