71562023-12-31 22:45:14xxxTáblajáték 2 (70 pont)cpp17Accepted 70/703ms3680 KiB
#include <bits/stdc++.h>
using namespace std;

void kivonas(deque<int> &q) {
    int cnt = 0;
    while(true) {
        auto t = q.begin();
        q.pop_front();
        if (*t > 0) {
            q.push_front(*t-1);
            while(cnt--) {
                q.push_front(2);
            }
            return;
        } else {
            cnt++;
        }
    }
}

void hozzaad(deque<int> &q) {
    int cnt = 0;
    while(true) {
        auto t = q.begin();
        q.pop_front();
        if (*t < 2) {
            q.push_front(*t+1);
            while(cnt--) {
                q.push_front(0);
            }
            return;
        } else {
            cnt++;
        }
    }
}

int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;
    cin >> n;
    vector<int> a(n);

    int sum = 0;
    for(int &i : a) {
        cin >> i;
    }

    int sor = 0;
    deque<int> q;

    for(int i = 0; i < n; ++i) {
        if (a[i] == 0) {
            ++sor;
            q.push_front(0);
        } else if (a[i] == 1) {
            ++sor;
           q.push_front(1);
        } else if (a[i] == 2) {
            ++sor;
            q.push_front(2);
        } else if (a[i] == 3) {
            --sor;
            q.pop_front();
        } else if (a[i] == 4) {
            kivonas(q);
        } else if (a[i] == 5) {
            hozzaad(q);
        }
    }

    cout << sor << '\n';

    bool OK = false;

    for(auto it = q.rbegin(); it != q.rend(); ++it) {
        if (*it > 0) OK = 1;
        if (OK) cout << *it;
    }
    if (!OK) cout << 0 << '\n';

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base70/70
1Accepted0/03ms1828 KiB
2Accepted0/03ms2204 KiB
3Accepted2/23ms2352 KiB
4Accepted3/33ms2352 KiB
5Accepted3/33ms2564 KiB
6Accepted3/33ms2792 KiB
7Accepted3/33ms2860 KiB
8Accepted3/33ms2868 KiB
9Accepted3/33ms2940 KiB
10Accepted3/33ms2848 KiB
11Accepted3/33ms2856 KiB
12Accepted3/33ms2960 KiB
13Accepted3/33ms2948 KiB
14Accepted3/33ms2948 KiB
15Accepted4/43ms3052 KiB
16Accepted4/43ms3012 KiB
17Accepted4/43ms3016 KiB
18Accepted4/43ms3140 KiB
19Accepted4/43ms3372 KiB
20Accepted4/43ms3484 KiB
21Accepted4/43ms3340 KiB
22Accepted4/43ms3472 KiB
23Accepted3/33ms3680 KiB