247102026-02-14 14:41:01PKBTáblajáték 2 (70 pont)cpp14Accepted 70/701ms540 KiB
#include <iostream>
#include <vector>
using namespace std;

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

    int sor = 0;

    vector<int> d = {0};

    for (int k = 0; k < K; k++) {
        int step;
        cin >> step;

        if (step == 0) {
            d.push_back(0);
            sor++;
        }
        else if (step == 1) {
            d.push_back(1);
            sor++;
        }
        else if (step == 2) {
            d.push_back(2);
            sor++;
        }
        else if (step == 3) {
            if (d.size() > 1)
                d.pop_back();
            else
                d[0] = 0;
            sor--;
        }
        else if (step == 4) {
            int i = d.size() - 1;
            while (i >= 0 && d[i] == 0) {
                d[i] = 2;
                i--;
            }
            if (i >= 0) d[i]--;
        }
        else if (step == 5) {
            int i = d.size() - 1;
            while (i >= 0 && d[i] == 2) {
                d[i] = 0;
                i--;
            }
            if (i >= 0) d[i]++;
        }
    }

    int start = 0;
    while (start + 1 < d.size() && d[start] == 0) start++;

    cout << sor << "\n";

    for (int i = start; i < d.size(); i++)
        cout << d[i];
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base70/70
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted2/21ms316 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted3/31ms332 KiB
9Accepted3/31ms508 KiB
10Accepted3/31ms540 KiB
11Accepted3/31ms316 KiB
12Accepted3/31ms316 KiB
13Accepted3/31ms316 KiB
14Accepted3/31ms500 KiB
15Accepted4/41ms316 KiB
16Accepted4/41ms316 KiB
17Accepted4/41ms316 KiB
18Accepted4/41ms316 KiB
19Accepted4/41ms316 KiB
20Accepted4/41ms316 KiB
21Accepted4/41ms316 KiB
22Accepted4/41ms316 KiB
23Accepted3/31ms508 KiB