71552023-12-31 22:44:29xxxTáblajáték 2 (70 pont)cpp17Partially correct 68/703ms3724 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;

    }

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base68/70
1Accepted0/03ms1828 KiB
2Accepted0/03ms2020 KiB
3Accepted2/23ms2232 KiB
4Accepted3/32ms2312 KiB
5Accepted3/33ms2548 KiB
6Accepted3/33ms2632 KiB
7Accepted3/33ms2652 KiB
8Accepted3/33ms2740 KiB
9Accepted3/33ms2968 KiB
10Accepted3/33ms2952 KiB
11Accepted3/32ms2952 KiB
12Accepted3/33ms3176 KiB
13Accepted3/33ms3388 KiB
14Accepted3/33ms3472 KiB
15Accepted4/43ms3372 KiB
16Accepted4/43ms3500 KiB
17Accepted4/43ms3592 KiB
18Accepted4/43ms3584 KiB
19Accepted4/43ms3596 KiB
20Accepted4/43ms3696 KiB
21Accepted4/43ms3696 KiB
22Accepted4/43ms3700 KiB
23Partially correct1/33ms3724 KiB