This may be the cause of the NZEC. Try putting a try{...}catch (OutOfMemoryError e){} around your solution and if you just get WA, then that was the problem.
However, there are two questions you should be asking yourself - 1 is whether they need to be longs, and the other is whether the array really needs to be two-dimensional.