fork download
  1. #作者堀江会津大学オンラインジャッジ問0122に合格したコード
  2. while True:
  3. e=list(map(int,input().split()))
  4. if e[0]==0 and e[1]==0:break
  5. n=int(input())*2
  6. xs=list(map(int,input().split()))
  7. st=[e]
  8. for i in range(0,n,2):
  9. x=xs[i]
  10. y=xs[i+1]
  11. st2=[]
  12. for e2 in [[-1,-1],[-1,0],[-1,1],[0,-1],[0,0],[0,1],[1,-1],[1,0],[1,-1]]:
  13. x2=x+e2[0]
  14. y2=y+e2[1]
  15. if x2<0 or 9<x2 or y2<0 or 9<y2:continue
  16. for [x3,y3] in st:
  17. dx=abs(x3-x2)
  18. dy=abs(y3-y2)
  19. if (dx==2 and dy<=1) or (dx<=1 and dy==2):
  20. st2.append([x2,y2])
  21. break
  22. st=st2
  23. if len(st)>0:
  24. print("OK")
  25. else:
  26. print("NA")
Success #stdin #stdout 0.03s 9668KB
stdin
6 1
10
6 4 3 3 1 2 0 5 4 6 1 8 5 9 7 7 8 6 8 3
6 1
10
6 4 3 3 1 2 0 5 4 6 1 8 5 9 7 7 8 6 9 0
0 0
stdout
OK
NA