NZEC: how to get error details?

Hi all!
I’m new to codeChef, I’m trying to solve this “easy” problem Cherry and pyramid and can’t figure out how to read data.
It keeps getting NZEC error. Before to submit, I run against the sample input and it works as expected, but after submit, it only says NZEC and no more datails are given.
my solution

How to read inputs in Java in CodeChef?
I’m not sure the input reading is actual the problem, this NZEC message is very dubious.

2 Likes

I don’t think there is any issue with the input. Is your logic correct? I guess there is some input for which your code is breaking.

1 Like

thanks for quick guidance!
it runs OK in my IDE.
I have no idea what’s wrong, it only says NZEC (??). Probably some exception is being thrown, but it’s very hard to figure which and where.

i tried using string instead of sb. it removes the NZEC but it gives TLE so i think u need to optimise it as well!

First of all, well stated question!

NZEC is shorthand for non-zero exit code; or in clearer language: an exception occured.
I don’t have much experience with Java, but I think the issue is the following:

StringBuilder sb = new StringBuilder();
for (int i = 0; i < line; i++) {
    sb.append(str);
    if (sb.length() > line) {
        int removeLasts = sb.length() - line;
        iThLine = sb.substring(0, sb.length() - removeLasts);
    }
}

In the worst case sb will get a length of N\cdot S=10^9\cdot 10^5=10^{14} which will definitely not fit in memory. It seems that Codechef does not have a MLE (memory limit exceeded) but instead gives NZEC.

This issue happens because you don’t break out of the loop when you have found your iThLine. However when you would have broken out of the loop the length will be at most 10^9, which is probably still be too much memory.

To solve it you will need to improve your algorithm, to fit in memory and time bounds. The bounds require some slightly advanced topics, which you might not yet know. There is a part of the solution I think you should be able to find. For that try to think how you, as a human, would approach the following test case:

aaaaab
aa
1
1000000000

when you solve that and can implement it (or when you have tried to for a long while), read the editorial for the extra bit of knowledge to get AC.

3 Likes