How to debug on Codechef's IDE

Hello folks,

I’m new to codechef and just yesterday I tried to submit my solution in the practice segment. After initial hastles with NZEC, I submitted the program. However, now it tells me that the Time Limit has exceeded. Is there any way to know what input caused that? I tired a couple of Boundary conditions in my local IDE (IntelliJ) and it works fine and executes before timelimit. I wonder if a specific(unhandled) input is causing the issue. Is there anyway to know what Test scenarios are fed to program once it’s submitted and what are the results of these tests?

No, the testcases are (deliberately) kept secret. You’ll have to employ some ingenuity, observation and insight to try and work out why your program is timing out :slight_smile:

Try optimizing your approach. TLE is avoidable with careful optimization of your code.

Assuming the problem you’re trying to solve is ISHVALA, here’s something to start you off :slight_smile: Hopefully I haven’t made any mistakes with reading the question …

Try this testcase (3.8MB).

It was generated via this program, which I designed to a) fit the given constraints of the problem and b) hit your program with a case that will cause it to timeout :slight_smile:

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    const int T = 100;
    cout << T << endl;
    for (int t = 0; t < T; t++)
    {
        const int N = 10'000;
        const int M = 10'000;
        cout << N << " " << M << endl;

        const int S = 2;

        auto generateRivers = [S](const int maxPos)
        {
            vector<int> riverPositions;
            int riverPos = 1;
            while (riverPos < maxPos)
            {
                riverPos = riverPos + S + (rand() % 2);
                if (riverPos <= maxPos)
                    riverPositions.push_back(riverPos);
            }
            return riverPositions;
        };

        const vector<int> horizontalRivers = generateRivers(N);
        const vector<int> verticalRivers = generateRivers(M);

        auto printRivers = [](const vector<int> riverPositions)
        {
            for (int i = 0; i < riverPositions.size(); i++)
            {
                cout << riverPositions[i];
                if (i != riverPositions.size() - 1)
                    cout << " ";
            }
            cout << endl;
        };

        cout << horizontalRivers.size() << " " << verticalRivers.size() << " " << S << endl;
        printRivers(horizontalRivers);
        printRivers(verticalRivers);

    }
}

For reference, the Problem Setter’s C++ solution takes 0.21 seconds to process this testcase. The time limit for C++ for this problem is 0.5 seconds, so I think the Java one is about twice that(?)

1 Like