×

# Run time error NZEC.

 0 / package codechef; // don't place package name! / import java.util.*; class coins { public static void main (String[] args) { Scanner in = new Scanner(System.in); int test; int numOfGames; int initial; int rounds; int target; //System.out.println("Enter the number of test cases:"); test = in.nextInt(); while (test-- != 0){ //System.out.println("Enter the number of games:"); numOfGames = in.nextInt(); while (numOfGames-- != 0){ //System.out.println("Enter initial, rounds and target:"); initial = in.nextInt(); rounds = in.nextInt(); target = in.nextInt(); int[] coins = new int[rounds]; for (int i=0; i

 0 In this problem, you don't even need to create an array. It's a very simple logic Let's say we have N number of rounds to be an even number. For example - 4 Now we know either they all have to be tail or head. Let's say we have head {H H H H} Now the logic is if we have N to be even number, we divide it by 2 which is The answer will be (N/2) So the above head will end up be {H T H T} so when we have an even number of rounds and coins, it doesn't matter if the coin is head or tail The problem comes up when we have odd numbers of rounds and coins. For example, we have 5 number of rounds and coin. This time let's say we have tail {T T T T T} Now the result will be {H T H T H} and we need to find the number of tails in the result Here's the logic if the given coins are the tail and an odd number of coins and rounds. The result will be (N/2)+1 if we're finding the same coin in the result as the coin given in the question. if we had to find the Head in the above question then we simply do (N/2). I hope that helps, you can check out my solution for this problem. https://www.codechef.com/viewsolution/14531353 answered 20 Jul '17, 03:23 2★kunnu120 518●9 accept rate: 5% 2 He knows this. See his submissions. He asked this question after successfully submitting using the correct logic. He just wanted to know what was wrong with his above approach. (20 Jul '17, 15:24)
 1 The problem link is https://www.codechef.com/problems/CONFLIP . You are getting NZEC (which means runtime error) because the max input value for N (here rounds) is 10^9 . You are therefore trying to create an array with 10^9 elements, which is not allowed in java. The max number of elements that the compiler will allow is 10^9, but in reality, whenever the number of elements is > around 4.4*10^7, java will give a runtime error. So, try to limit the number of elements in an array to 10^7. Hope that answered your question. :) I would also suggest you take a look at this - http://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/ answered 20 Jul '17, 01:23 875●2●14 accept rate: 10%
 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:

×525
×231

question asked: 19 Jul '17, 20:22

question was seen: 392 times

last updated: 20 Jul '17, 15:24