Search code examples
compiler-constructionc++14

How codechef compiler works?


I want to know how the codechef compiler works. Actually not only codechef compiler how other competitive platforms compilers works on backend. Because the output which I used to get on my local compiler sometimes differ from the online compilers specifically on codechef.

For example on my local compiler when I am running the below code I am getting the correct output :

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    // your code goes here
    int t;
    cin >> t;
    while (t--)
    {
        int val, N, Z, count = 0, evacuate = 0;
        vector<int> v;
        cin >> N >> Z;
        for (int i = 0; i < N; i++)
        {
            cin >> val;
            v.push_back(val);
        }
        std::make_heap(v.begin(), v.end());
        while (Z > 0)
        {
            int power = v.front();
            Z = Z - power;
            std::pop_heap(v.begin(), v.end());
            v.pop_back();
            power = power / 2;
            if (power)
            {
                v.push_back(power);
                std::push_heap(v.begin(), v.end());
            }
            else if(power == 0 && Z > 0){
                evacuate = 1;
                break;
            }
            if (Z < 0)
            {
                count++;
                break;
            }
            count++;
        }
        if (evacuate)
            cout << "Evacuate" << endl;
        else
            cout << count << endl;
    }
}

while the same code when I am running on codechef compiler to solve codechef problem I am getting unexpected output (only 0's)

Screenshot for comparing both the output2

Also, the code working on cpp.sh.

How CodeChef Compiler Working and How the outputs in both are differing ? May be the problem can be on code too but locally, I am getting the correct outputs for the inputs provided manually.


Solution

  • Just checked, your code work just fine. The problem is that you didn't have anything for the input.

    Check the "custom input", then enter "1 5 25 7 13 8 17 3", and you would see the result as expected.

    Edit:

    enter image description here

    To do that, you would first check the checkbox in the red circle, then a text box would show underneath, where you can type in your test case in the blue box.