Code jam "Board Meeting" problem, what's wrong with my solution

problem: https://codingcompetitions.withgoogle.com/codejam/round/0000000000051708/000000000016c77c

my solution is getting RE.
my solution for N=1, https://ideone.com/gSmvtm
my technique is,

  1. i seek distance of king from (-1000000,-1000000) its d1
  2. i seek distance of king from (1000000,1000000) its d2
  3. so now king is either on (x1,y1)= (-1000000+d1, 1000000-d2) or on (x2,y2)= (1000000-d2, -1000000+d1)

sol for testing, https://ideone.com/khL4Ps
here suppose king position is (500,1000), its showing correct solution in my pc.