Submission #155956

# Submission time Handle Problem Language Result Execution time Memory
155956 2019-10-02T08:26:05 Z Minnakhmetov CATS (NOI14_cats) C++14
0 / 25
1500 ms 1228 KB
#include <bits/stdc++.h>
   
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
 
using namespace std;

struct MyStack {
    vector<int> v;
    int flip = 0;

    void push(int x)  {
        v.push_back(x);
    }

    int pop() {
        if (!v.empty()) {
            int x = v.back();
            v.pop_back();
            return x;
        }
        return flip;
    }

    int top() {
        return v.empty() ? flip : v.back();
    }
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int q;
    cin >> q;

    while (q--) {
        ll x, l, n;
        cin >> x >> l >> n;

        MyStack s1, s2;

        bool ok = false;
        int counter = x;
        while (counter > 0) {
            s2.push(s1.pop());
            for (int &i : s1.v)
                i ^= 1;
            s1.flip ^= 1;

            if (s2.top() > l) {
                ok = true;
                counter--;
            }
            else {
                if (ok)
                    exit(1);
                if (s2.v.empty())
                    s2.v.push_back(2 * n);
                else
                    s2.v.back() += 2 * n;
                s1.push(s2.top());
                s1.push(s2.top());
                s2.pop();
                s2.pop();
            }

            // for (int x : s1.v)
            //     cout << x << " ";
            // cout << "\n";
            // for (int x : s2.v)
            //     cout << x << " ";
            // cout << "\n";
            // cout << "\n";
        }

        cout << s2.top() << "\n";

        // COUNTER = X
        // WHILE COUNTER > 0
        // S2 PUSH T1 //Push the top element of S1 onto S2
        // S1 POP //Pop the top element of S1
        // FLIP LAST BINARY BIT OF ALL NUMBERS IN S1
        // IF T2 > L
        // COUNTER = COUNTER - 1
        // IF COUNTER == 0 PRINT T2
        // ELSE
        // S2 PUSH N
        // S2 PUSH N
        // S2 ADD
        // S2 ADD
        // S1 PUSH T2
        // S1 PUSH T2
        // S2 POP
        // S2 POP
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 376 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 376 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 380 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 104 ms 504 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1536 ms 1228 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1546 ms 1128 KB Time limit exceeded
2 Halted 0 ms 0 KB -