72142024-01-03 17:36:36MagyarKendeSZLGTáblajáték 2 (70 pont)cpp17Wrong answer 30/703ms3992 KiB
#include <bits/stdc++.h>

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()
#define has(s, e) s.count(e)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using u32 = unsigned int;

const int BITS = 200;
const int WORD_SIZE = 32;

struct Integer {
private:
    vector<u32> value;
public:
    Integer() : value((BITS + WORD_SIZE - 1) / WORD_SIZE, 0) {}

    void add() {
        for (size_t i = 0; i < value.size(); ++i) {
            if (value[i] == UINT_MAX) {
                value[i] = 0;
            } else {
                ++value[i];
                break;
            }
        }
    }

    void sub() {
        for (size_t i = 0; i < value.size(); ++i) {
            if (value[i] == 0) {
                value[i] = UINT_MAX;
            } else {
                --value[i];
                break;
            }
        }
    }

    void div3() {
        u32 carry = 0;
        for (int i = value.size() - 1; i >= 0; --i) {
            ull curr = ((ull)(value[i]) + (ull)(carry) * (UINT_MAX + 1));
            value[i] = (u32)(curr / 3);
            carry = (u32)(curr % 3);
        }
    }

    void mul3() {
        u32 carry = 0;
        for (size_t i = 0; i < value.size(); ++i) {
            ull curr = (ull)(value[i]) * 3 + carry;
            value[i] = (u32)(curr);
            carry = (u32)(curr >> WORD_SIZE);
        }
    }

    void print() const {
        vector<int> result;
        Integer tmp = *this;

        while (tmp.value != vector<u32>(tmp.value.size(), 0)) {
            int rem = 0;
            for (size_t i = tmp.value.size(); i > 0; --i) {
                ull curr = ((ull)rem << WORD_SIZE) + tmp.value[i - 1];
                tmp.value[i - 1] = (u32)curr / 3;
                rem = curr % 3;
            }
            result.push_back(rem);
        }

        if (result.empty()) {
            cout << '0';
        } else {
            for (int i = result.size() - 1; i >= 0; i--) {
                cout << result[i];
            }
        }
    }

};

int main() {
    speed;

    ll K, row = 0;
    cin >> K;

    Integer col;

    while (K--) {
        char m;
        cin >> m;

        if (m == '0') {
            row++;
            col.mul3();
        }
        else if (m == '1') {
            row++;
            col.mul3();
            col.add();
        }
        else if (m == '2') {
            row++;
            col.mul3();
            col.add();
            col.add();
        }
        else if (m == '3') {
            row--;
            col.div3();
        }
        else if (m == '4') {
            col.sub();
        }
        else {
            col.add();
        }
    }

    cout << row << '\n';
    col.print();
}
SubtaskSumTestVerdictTimeMemory
base30/70
1Accepted0/03ms2104 KiB
2Wrong answer0/03ms2220 KiB
3Accepted2/23ms2384 KiB
4Partially correct1/33ms2696 KiB
5Accepted3/33ms2692 KiB
6Partially correct1/33ms2876 KiB
7Accepted3/33ms3096 KiB
8Partially correct1/33ms3292 KiB
9Partially correct1/32ms3340 KiB
10Partially correct1/33ms3344 KiB
11Accepted3/33ms3628 KiB
12Partially correct1/33ms3364 KiB
13Partially correct1/33ms3600 KiB
14Partially correct1/33ms3604 KiB
15Partially correct1/43ms3588 KiB
16Partially correct1/43ms3720 KiB
17Partially correct1/43ms3876 KiB
18Partially correct1/43ms3728 KiB
19Partially correct1/43ms3732 KiB
20Partially correct1/43ms3992 KiB
21Partially correct1/42ms3852 KiB
22Partially correct1/42ms3856 KiB
23Accepted3/33ms3860 KiB