Submission #523290

# Submission time Handle Problem Language Result Execution time Memory
523290 2022-02-07T10:40:21 Z RaresFelix Odd-even (IZhO11_oddeven) C++17
100 / 100
2 ms 296 KB
#include <bits/stdc++.h>

using namespace std;
const int MC = 271;

struct Big {
    int len, V[MC];
    void read() {
        string s;
        cin >> s;
        len = s.size();
        for(int i = len; i >= 1; --i)
            V[i] = s[len - i] - '0';
    }
    Big() {
        len = 0;
        memset(V, 0, sizeof(V));
    }

    void pune(int v) {
        len = 0;
        memset(V, 0, sizeof(V));
        while (v)
            V[++len] = v % 10, v /= 10;
    }

    void ref() {
        int tr = 0;
        for (int i = 1; i <= len; ++i) {
            V[i] += tr;
            tr = 0;
            if (V[i] >= 10)
                tr = V[i] / 10;
            else if (V[i] < 0){
                while(V[i] < 0)
                    --tr, V[i] = V[i] + 10;
            }
            V[i] %= 10;
        }
        while (tr) V[++len] = tr % 10, tr /= 10;
        while (len && !V[len]) --len;
    }

    Big operator*(const Big &b) const {
        Big re;
        for (int i = 1; i <= len; ++i)
            for (int j = 1; j <= b.len; ++j)
                re.V[i + j - 1] += V[i] * b.V[j];
        re.len = len + b.len - 1;
        re.ref();
        return re;
    }

    Big operator*(const int &v) const {
        Big re;
        for (int i = 1; i <= len; ++i)
            re.V[i] += V[i] * v;
        re.len = len;
        re.ref();
        return re;
    }

    Big operator/(const int &v) const {
        Big re;
        int tr = 0;
        re.len = len;
        for (int i = len; i >= 1; --i)
            tr += V[i], re.V[i] = tr / v, tr %= v, tr *= 10;
        re.ref();
        return re;
    }

    Big operator+(const int &v) const {
        Big re;
        re = (*this);
        re.V[1] += v;
        re.ref();
        return re;
    }

    Big operator-(const int &v) const {
        Big re;
        re = (*this);
        re.V[1] -= v;
        re.ref();
        return re;
    }
    Big operator+(const Big &b) const {
        Big re;
        re.len = max(len, b.len);
        for(int i = 1; i <= len; ++i) re.V[i] += V[i];
        for(int i = 1; i <= b.len; ++i) re.V[i] += b.V[i];
        re.ref();
        return re;
    }
    Big operator-(const Big &b) const {
        Big re;
        re.len = max(len, b.len);
        for(int i = 1; i <= len; ++i) re.V[i] += V[i];
        for(int i = 1; i <= b.len; ++i) re.V[i] -= b.V[i];
        re.ref();
        return re;
    }
    bool operator <(const Big &b) const {
        if(len != b.len) return len < b.len;
        for(int i = len; i >= 1; --i)
            if(V[i] != b.V[i]) return V[i] < b.V[i];
        return 0;
    }
    Big(int v) {
        pune(v);
    }
    void afis() {
        for(int i = len; i >= 1; --i)
            cout << V[i];
        cout << "\n";
    }
};


int main() {
    Big n, st(1), dr, mij, t1, t2;
    n.read();
    dr = n;
    while (st < dr) {
        mij = (st + dr + 1) / 2;
        t1 = mij * (mij + 1);
        t2 = n * 2;
        if (t1 < t2) st = mij;
        else dr = mij - 1;
    }
    Big re = n * 2;
    re = re - st;
    re = re - 1;
    if(!re.len) re.len = re.V[1] = 1;
    re.afis();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 2 ms 296 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct