71542023-12-31 22:14:40xxxTáblajáték 2 (70 pont)cpp17Partially correct 42/703ms3480 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';

    for(auto it = q.rbegin(); it != q.rend(); ++it) {
        cout << *it;
    }

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base42/70
1Accepted0/03ms2008 KiB
2Accepted0/03ms2144 KiB
3Partially correct1/23ms2344 KiB
4Partially correct1/33ms2216 KiB
5Partially correct1/33ms2276 KiB
6Partially correct1/33ms2504 KiB
7Accepted3/33ms2768 KiB
8Accepted3/33ms2640 KiB
9Accepted3/33ms2636 KiB
10Accepted3/33ms2828 KiB
11Partially correct1/33ms2896 KiB
12Partially correct1/33ms2996 KiB
13Accepted3/33ms2896 KiB
14Accepted3/33ms2892 KiB
15Accepted4/43ms3044 KiB
16Accepted4/43ms2964 KiB
17Partially correct1/43ms3100 KiB
18Partially correct1/43ms3268 KiB
19Partially correct1/43ms3348 KiB
20Partially correct1/43ms3352 KiB
21Partially correct1/43ms3352 KiB
22Accepted4/43ms3356 KiB
23Partially correct1/33ms3480 KiB