16252022-11-30 06:09:50kovacs.peter.18fTáblajátékcpp11Accepted 50/503ms3876 KiB
#include <iostream>
#include <vector>

using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int K;
    cin >> K;
    int row = 0, count;
    vector<int> digitS { 0 };
    while (K--) {
        int L;
        cin >> L;
        switch (L) {
            case 0:
                ++row;
                // *2
                if (digitS[0]) {
                    digitS.push_back(0);
                }
                break;
            case 1:
                ++row;
                // *2+1
                if (digitS[0]) {
                    digitS.push_back(1);
                }
                else {
                    digitS[0] = 1;
                }
                break;
            case 2:
                --row;
                // /2
                if (digitS.size() == 1) {
                    digitS[0] = 0;
                }
                else {
                    digitS.pop_back();
                }
                break;
            case 3:
                // -1
                for (count = 0; !digitS.back(); count++) {
                    digitS.pop_back();
                }
                if (digitS.size() == 1) {
                    digitS.pop_back();
                }
                else {
                    digitS.back() = 0;
                }
                while (count--) {
                    digitS.push_back(1);
                }
                break;
            case 4:
                // +1
                for (count = 0; !digitS.empty() && digitS.back(); count++) {
                    digitS.pop_back();
                }
                if (!digitS.empty()) {
                    digitS.back() = 1;
                }
                else {
                    digitS.push_back(1);
                }
                while (count--) {
                    digitS.push_back(0);
                }
                break;
        }
    }
    cout << row << '\n';
    for (auto e : digitS) {
        cout << e;
    }
    cout << '\n';
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1824 KiB
2Accepted0/02ms2060 KiB
3Accepted3/32ms2292 KiB
4Accepted3/32ms2468 KiB
5Accepted3/32ms2672 KiB
6Accepted3/32ms2832 KiB
7Accepted3/32ms3216 KiB
8Accepted3/32ms3348 KiB
9Accepted3/32ms3272 KiB
10Accepted3/32ms3392 KiB
11Accepted3/32ms3468 KiB
12Accepted3/32ms3568 KiB
13Accepted4/42ms3696 KiB
14Accepted4/42ms3776 KiB
15Accepted4/42ms3780 KiB
16Accepted4/42ms3876 KiB
17Accepted4/42ms3676 KiB