ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1298. Knight

It's strange. My prog runs faster when n=8 than when n=7.
Re: It's strange. My prog runs faster when n=8 than when n=7.
Posted by ER 5 May 2014 11:22
If you use a simple depth first search, your run time will depend on the order in which you examine the possible moves.

For example, always examining the moves in this order yields a TLE: (1,2), (1,-2), (-1,2), (-1,-2), (2,1), (2,-1), (-2,1), (-2,-1).

To get the fastest solutions you'll want to adapt the search order at each node in the search tree, but you can get an AC  with a static search order.