×

# Why does this code throw NZEC?

 0 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(); } }  asked 27 Nov '14, 08:18 0★ghurtado 1 accept rate: 0%

 1 Refer to this link HERE link This answer is marked "community wiki". answered 27 Nov '14, 19:48 252●1●6●24 accept rate: 0% 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. (28 Nov '14, 10:46) ghurtado0★
 0 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 ;-) answered 27 Nov '14, 16:16 16.9k●49●115●225 accept rate: 11%
 0 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). link This answer is marked "community wiki". answered 28 Nov '14, 10:44 0★ghurtado 1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,302
×422

question asked: 27 Nov '14, 08:18

question was seen: 873 times

last updated: 28 Nov '14, 10:46