79512024-01-12 08:27:55AblablablaTáblajáték 2 (70 pont)cpp17Accepted 70/703ms4264 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

string elem = "0";

void hozzaad(){
    int ind = elem.size() - 1;

    while(ind >= 0 && elem[ind] == '2'){
        elem[ind] = '0';
        ind--;
    }

    if(ind == -1){
        elem = "1" + elem;
    } else{
        if(elem[ind] == '0'){
            elem[ind] = '1';
        } else{
            elem[ind] = '2';
        }
    }
}

void kivon(){
    int ind = elem.size() - 1;

    while(ind >= 0 && elem[ind] == '0'){
        elem[ind] = '2';
        ind--;
    }

    if(elem[ind] == '1'){
        elem[ind] = '0';

        while(elem[0] == '0'){
            elem.erase(elem.begin());
        }

        if(elem.size() == 0){
            elem = "0";
        }
    } else{
        elem[ind] = '1';
    }
}

int main()
{
    int k;
    cin >> k;

    int sor = 0;

    for(int i = 0; i < k; i++){
        int a;
        cin >> a;

        if(a == 0){
            sor++;
            elem += '0';

            if(elem == "00"){
                elem = "0";
            }
        } else if(a == 1){
            sor++;
            elem += '1';

            if(elem == "01"){
                elem = "1";
            }
        } else if(a == 2){
            sor++;
            elem += '2';

            if(elem == "02"){
                elem = "2";
            }
        } else if(a == 3){
            sor--;
            elem.pop_back();
            if(elem.size() == 0){
                elem = "0";
            }
        } else if(a == 4){
            kivon();
        } else{
            hozzaad();
        }
    }

    cout << sor << "\n";
    cout << elem << "\n";
}
SubtaskSumTestVerdictTimeMemory
base70/70
1Accepted0/03ms1812 KiB
2Accepted0/03ms2060 KiB
3Accepted2/23ms2140 KiB
4Accepted3/33ms2228 KiB
5Accepted3/33ms2472 KiB
6Accepted3/33ms2652 KiB
7Accepted3/33ms2864 KiB
8Accepted3/33ms3076 KiB
9Accepted3/33ms3156 KiB
10Accepted3/33ms3288 KiB
11Accepted3/33ms3368 KiB
12Accepted3/33ms3408 KiB
13Accepted3/33ms3636 KiB
14Accepted3/33ms3872 KiB
15Accepted4/43ms3984 KiB
16Accepted4/43ms3956 KiB
17Accepted4/43ms3884 KiB
18Accepted4/42ms3856 KiB
19Accepted4/43ms3976 KiB
20Accepted4/43ms3988 KiB
21Accepted4/43ms4216 KiB
22Accepted4/43ms4264 KiB
23Accepted3/32ms4260 KiB