Why does this code throw NZEC?

I’ve been racking my brain over this for hours and I can’t figure out why I keep getting NZEC when submitting to CodeChef. I am generally good with these problems, but this one escapes me. The code runs fine locally:

package CodeChef.LeftRightTree;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
// @link: http://www.codechef.com/problems/CHEFLR
public class Main {
	public static void main(String args[]) throws Exception {
		int numTurns;
		int currentLine = 0;
		String line;
		char direction;
		boolean isEven;
		BigInteger currentNode;
		BigInteger mod = new BigInteger("1000000007");

		BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		
		line = buffer.readLine();
		numTurns = Integer.parseInt(line);

		while (currentLine++ < numTurns) {
			currentNode = new BigInteger("1");
			
			line = buffer.readLine();

			for (int i = 0; i < line.length(); i++) {
				direction = line.charAt(i);
				isEven = currentNode.mod(new BigInteger("2")).equals(BigInteger.ZERO);
				
				currentNode = currentNode.multiply(new BigInteger("2"));
				
				if(isEven){ // node ID is even
					currentNode = currentNode.add(new BigInteger("-1"));
				}
				
				if(direction == 'r'){
					currentNode = currentNode.add(new BigInteger("2"));
				}
			}

			out.println(currentNode.mod(mod));
		}
		
		out.flush();
	}
}

And you tried your code with 5 (test cases) x 105 digits long string with all 'l' (L characters only)?

Tip: write a program to generate such input file and the use it for testing :wink:

Refer to this link HERE

1 Like

In the end the issue was embarrassingly simple: I had left in the package declaration.

package CodeChef.LeftRightTree;

After removing it, my program runs.

Unfortunately, it looks like I can’t accept my own answer, but this should definitely be part of the NZEC FAQ (if one exists).

Sorry, but that’s not helpful at all. The answer you linked to only gives the definition of NZEC, which is very basic and I already knew.