I just joined CodeChef and trying to solve Temple Land problem. The link to the problem is : TEMPLELA Problem - CodeChef. I’ve written following code for the problem :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int Num_of_Strips;
Console.WriteLine("Enter the number of strips to look at(1<=Number of Strips<=100) : ");
Num_of_Strips = int.Parse(Console.ReadLine());
int[] Num = new int[Num_of_Strips+1];
int flag = 0;
for(int i=0;i<Num_of_Strips;i++)
{
Console.WriteLine("Enter the length of Strip" + (i+1) +" : ");
Num[i + 1] = int.Parse(Console.ReadLine());
int[] height = new int[Num[i + 1]+1];
for (int j = 1; j <= Num[i + 1];j++)
{
Console.WriteLine("Enter the height of part" + j + " : ");
height[j] = int.Parse(Console.ReadLine());
}
if((height[1] == 1)&&(height[Num[i + 1]] == 1))
{
if(Num[i + 1]%2 == 1)
{
int Centre_Position = (Num[i + 1] + 1) / 2;
for(int k = 1; k<= Num[i + 1];k++)
{
if((k>1) && (k<=Centre_Position))
{
if(height[k] == height[k-1]+1)
{
flag = 1;
}
else
{
flag = 0;
break;
}
}
else if((k>Centre_Position) && (k< Num[i + 1]))
{
if(height[k] == height[k-1]-1)
{
flag = 1;
}
else
{
flag = 0;
break;
}
}
}
if(flag == 0)
{
Console.WriteLine("no");
}
else
{
Console.WriteLine("yes");
}
}
else
{
Console.WriteLine("no");
}
}
else
{
Console.WriteLine("no");
}
}
Console.ReadKey();
}
}
}
This code is working fine in my System incuding other two systems I’ve checked it with and providing correct output. Don’t know why it is giving Runtime Error(NZEC) while submitting the solution. Can anyone help me in detecting if there is any problem in the code or why it is giving such error whie uploading to codechef.