Got an issue with a NZEC error and I can’t see what’s wrong. It works fine on my machine with the test example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int cases = int.Parse(Console.ReadLine());
for (int i = 0; i < cases; i++)
{
// read
int[] gridDim = ReadIntArray();
int[,] grid = new int[gridDim[0], gridDim[1]];
int[] startPos = ReadIntArray();
int[] endPos = ReadIntArray();
startPos[0] -= 1;
startPos[1] -= 1;
endPos[0] -= 1;
endPos[1] -= 1;
for (int j = 0; j < gridDim[1]; j++)
{
int[] gridRow = ReadIntArray();
for (int k = 0; k < gridDim[0]; k++)
{
grid[j, k] = gridRow[k];
}
}
Console.WriteLine(numPassed(grid,startPos,endPos));
}
return;
}
static int[] ReadIntArray()
{
string instring = System.Console.ReadLine();
return instring.Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
}
static int numPassed(int[,] grid, int[] curPos, int[] destPos)
{
// move is valid?
if (curPos[0] < 0 || curPos[1] < 0) return 0;
if (curPos[0] > grid.GetLength(0)-1 || curPos[1] > grid.GetLength(1)-1) return 0;
if (grid[curPos[0], curPos[1]] == 0) return 0;
// has passed?
{
int sum = 0;
foreach (int i in grid)
{
sum +=i;
if (sum > 1) break;
}
if (sum == 1)
{
if (curPos.SequenceEqual(destPos))
{return 1;}
else
{return 0;}
}
}
// attempt move
int[,] postMove = (int[,]) grid.Clone();
// shrink height
postMove[curPos[0],curPos[1]] -= 1;
int passedCount = 0;
passedCount += numPassed(postMove, new int[2] {curPos[0]+1,curPos[1]}, destPos);
passedCount += numPassed(postMove, new int[2] {curPos[0]+2,curPos[1]}, destPos);
passedCount += numPassed(postMove, new int[2] {curPos[0]-1,curPos[1]}, destPos);
passedCount += numPassed(postMove, new int[2] {curPos[0]-2,curPos[1]}, destPos);
passedCount += numPassed(postMove, new int[2] {curPos[0],curPos[1]+1}, destPos);
passedCount += numPassed(postMove, new int[2] {curPos[0],curPos[1]+2}, destPos);
passedCount += numPassed(postMove, new int[2] {curPos[0],curPos[1]-1}, destPos);
passedCount += numPassed(postMove, new int[2] {curPos[0],curPos[1]-2}, destPos);
return passedCount;
}
}
}