document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. class World {
  2.     void DFS(int depth) const {
  3.         size_t hash = calcHash();
  4.         if (!hashes.insert(hash).second) // we have already seen this state
  5.             return;
  6.  
  7.         if (we are already working more than 90ms since the start of the step)
  8.             throw TLException();
  9.  
  10.         if (depth == 0) {
  11.             int score = calcScore();
  12.             if (score > bestScore) {
  13.                 bestScore = score;
  14.                 bestActions = currentActions;
  15.             }
  16.             return;
  17.          }
  18.  
  19.          for (const Action& action : all valid actions) {
  20.              World w = *this;
  21.              w.performAction(action);
  22.              w.DFS(depth - 1);
  23.          }
  24.     }
  25. };
  26.  
  27. int main() {
  28.     ...
  29.  
  30.     vector<Action> actions;
  31.     try {
  32.         for (int depth=6; ; ++depth) {
  33.             DFS(depth);
  34.             actions = bestActions;
  35.         }
  36.     } catch (const TLException&) {}
  37.    
  38.     print out *actions.begin();
  39. }
');