You are not logged in. Please login at www.codechef.com to post your questions!

×

Nzec error while submitting ?

Nzec error while submitting ? While it runs well in my pc ?

This question is marked "community wiki".

asked 16 Sep '17, 21:18

arvind2128's gravatar image

2★arvind2128
11
accept rate: 0%

edited 16 Sep '17, 21:19

// My code is import java.lang.*; import java.util.Scanner; class Temple { public static boolean check() { Scanner s = new Scanner(System.in); int i=0,n=0; int arr[]= new int[100]; n=s.nextInt(); for(i=0;i<n;i++) arr[i]="s.nextInt();" if(n%2="=0||n&lt;3||n">100) return false; int h=n/2; for(i=1;i<=h;i++) { if((arr[h-i]!=arr[h+i])||((arr[h-i]+1)!=(arr[h-i+1]))) return false; } return true; }

(16 Sep '17, 21:20) arvind21282★

// And its main. public static void main(String[] args) { Scanner sc = new Scanner(System.in); int s=0; int i=0; s=sc.nextInt(); for(i=0;i<s;i++) { if(check()) System.out.println("Yes"); else System.out.println("No"); } } }

(16 Sep '17, 21:21) arvind21282★

Hey,

You are initializing the array in a wrong way.

You should declare array as

int N= in.nextInt();

int arr[] = new int[N];

I hope this resolves the problem...

Please UPVOTE...

(16 Sep '17, 21:26) taran_14076★

NZEC error is basically NON ZERO EXIT CODE.

In java, the prime reason for this is IndexOutOfBounds Exception, whether it may be string index or array...

Although NZEEC is given by any Exception thrown, IndexOutOfBounds Exception is prime reason for probably 95% NZEC submissions...

Hope this clarfies any doubt....

Please UPVOTE and Accept the answer if you find this helpful...

link

answered 16 Sep '17, 21:23

taran_1407's gravatar image

6★taran_1407
3.9k2791
accept rate: 22%

The problem TEMPLELA has a simpler solution.

When N is even, answer is invalid as there's no possible heights satisfying all requirements...

When N is odd, observe ans for Odd values of N

N = 3: 1 2 1

N = 5: 1 2 3 2 1

N = 7: 1 2 3 4 3 2 1

A single loop in java

int N = in.nextInt();

int[] height = new int[N];

boolean ans = true;

for(int i = 0; i<N; i++)height[i] = in.nextInt();

for(int i = 0; i< N; i++){

   if(i < (N-1)/2){

           if(height[i] != i+1)ans = false;

   }else if(i == (N-1)/2){

           if(height[i] != (N+1)/2)ans = false;

   }else{

           if(height[i] != N - i)ans = false;

   }

}

if(ans && (N%2 != 0))System.out.println("yes");

else System.out.println("no");

PS: I know i shouldn't post the whole solution, but it's your first one, so cheers...

Please UPVOTE if you find this helpful....

My code

link

answered 16 Sep '17, 21:39

taran_1407's gravatar image

6★taran_1407
3.9k2791
accept rate: 22%

edited 16 Sep '17, 22:03

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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

question asked: 16 Sep '17, 21:18

question was seen: 212 times

last updated: 16 Sep '17, 22:03