2891 2023. 02. 02 09:31:05 tamasmark Táblajáték cpp17 Elfogadva 50/50 3ms 3920 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
Részfeladat Összpont Teszt Verdikt Idő Memória
base 50/50
1 Elfogadva 0/0 3ms 1816 KiB
2 Elfogadva 0/0 3ms 2000 KiB
3 Elfogadva 3/3 3ms 2216 KiB
4 Elfogadva 3/3 3ms 2300 KiB
5 Elfogadva 3/3 2ms 2428 KiB
6 Elfogadva 3/3 3ms 2816 KiB
7 Elfogadva 3/3 3ms 2860 KiB
8 Elfogadva 3/3 2ms 2940 KiB
9 Elfogadva 3/3 2ms 3072 KiB
10 Elfogadva 3/3 3ms 3312 KiB
11 Elfogadva 3/3 2ms 3312 KiB
12 Elfogadva 3/3 2ms 3304 KiB
13 Elfogadva 4/4 3ms 3432 KiB
14 Elfogadva 4/4 3ms 3664 KiB
15 Elfogadva 4/4 3ms 3720 KiB
16 Elfogadva 4/4 3ms 3828 KiB
17 Elfogadva 4/4 3ms 3920 KiB