34102023-02-27 13:26:34EyusieTáblajátékcpp17Accepted 50/503ms3824 KiB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int lep;
    int sor = 0;
    vector<char> eredm;
    cin >> lep;
    int act;
    eredm.push_back('0');
    for(int i = 0, n = 0; i < lep; i++)
    {
        cin >> act;
        if(act == 0)
        {
            eredm.push_back('0');
            sor++;
        }
        if(act == 1)
        {
            eredm.push_back('1');
            sor++;
        }
        if(act == 2)
        {
            eredm.pop_back();
            sor--;
        }
        if(act == 3)
        {
            n=0;
            while(eredm[eredm.size()-1] == '0' && eredm.size() > 0)
            {
                eredm.pop_back();
                n++;
            }
            eredm.pop_back();
            eredm.push_back('0');
            for(int j = 0; j < n; j++)
            {
                eredm.push_back('1');
            }
        }
        if(act == 4)
        {
            n=0;
            while(eredm[eredm.size()-1] == '1' && eredm.size() > 0)
            {
                eredm.pop_back();
                n++;
            }
            eredm.pop_back();
            eredm.push_back('1');
            for(int j = 0; j < n; j++)
            {
                eredm.push_back('0');
            }
        }
    }
    cout << sor << "\n";
    int kezdet = 0;
    for(int i = 0; i < eredm.size(); i++)
    {
        if(eredm[i] == '0') kezdet++;
        else break;
    }
    for(int i = kezdet; i < eredm.size(); i++)
    {
        cout << eredm[i];
    }
    if(kezdet == eredm.size()) cout << "0\n";
    else cout << "\n";

}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1808 KiB
2Accepted0/03ms1904 KiB
3Accepted3/33ms2108 KiB
4Accepted3/33ms2320 KiB
5Accepted3/33ms2552 KiB
6Accepted3/33ms2612 KiB
7Accepted3/33ms2756 KiB
8Accepted3/33ms2812 KiB
9Accepted3/33ms3052 KiB
10Accepted3/33ms3176 KiB
11Accepted3/33ms3264 KiB
12Accepted3/33ms3384 KiB
13Accepted4/43ms3464 KiB
14Accepted4/43ms3532 KiB
15Accepted4/43ms3800 KiB
16Accepted4/43ms3704 KiB
17Accepted4/43ms3824 KiB