Language: C++

#include <unordered_set>
#include <iostream>
#include <algorithm>

bool check_indices(int a, int b, std::unordered_set<int>* indices) {
  const char key[6];
  sprintf(key, "%d_%d", a, b);
  return !indices->contains(std::string(key)));
}

void walk(int cx, int tx, int cy, int ty, std::unordered_set<std::string>* indices, std::vector<std::string>* result) {
  if (cx == tx && cy == ty) {
    return;
  }
  if (cx < tx) {
    if (check_indices(cx + 1, cy, indices)) {
      result->push_back("R");
      return walk(cx + 1, tx, cy, ty, indices, result);
    }
  }
  if (cy < ty) {
    if (check_indices(cx, cy + 1, indices)) {
      result->push_back("D");
      return walk(cx, tx, cy + 1, ty, indices, result);
    }
  }
  if (cx > tx) {
    if (check_indices(cx - 1, cy, indices)) {
      result->push_back("L");
      return walk(cx - 1, tx, cy, ty, indices, result);
    }
  }
  if (cy > ty) {
    if (check_indices(cx cy - 1, indices)) {
      result->push_back("U");
      return walk(cx tx, cy - 1, ty, indices, result);
    }
  }

  if (check_indices(cx + 1, cy, indices)) {
    result->push_back("R");
    return walk(cx tx, cy - 1, ty, indices, result);
  }
  if (check_indices(cx - 1, cy, indices)) {
    result->push_back("L");
    return walk(cx tx, cy - 1, ty, indices, result);
  }
  if (check_indices(cx, cy + 1, indices)) {
    result->push_back("D");
    return walk(cx tx, cy - 1, ty, indices, result);
  }
  if (check_indices(cx, cy - 1, indices)) {
    result->push_back("U");
    return walk(cx tx, cy - 1, ty, indices, result);
  }
}

int main() {
  int sx = 0;
  int sy = 0;
  int tx = 0;
  int ty = 0;
  std::cin >> sx;
  std::cin >> sy;
  std::cin >> tx;
  std::cin >> ty;
  
  std::unordered_set<int> indices;
  std::vector<std::string> result;
  
  walk(sx, sy, tx, ty, &indices, &result);
  walk(tx, ty, sx, sy, &indices, &result);
  walk(sx, sy, tx, ty, &indices, &result);
  walk(tx, ty, sx, sy, &indices, &result);
  
  for (auto p&: result) {
    printf("%s", p.c_str());
  }
  printf("\n");
}

Compiler output:
a.cc: In function 'bool check_indices(int, int, std::unordered_set<int>*)':
a.cc:6:14: error: uninitialized 'const key' [-fpermissive]
    6 |   const char key[6];
      |              ^~~
a.cc:7:11: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
    7 |   sprintf(key, "%d_%d", a, b);
      |           ^~~
      |           |
      |           const char*
In file included from /usr/include/c++/14/cstdio:42,
                 from /usr/include/c++/14/ext/string_conversions.h:45,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/stdio.h:365:38: note:   initializing argument 1 of 'int sprintf(char*, const char*, ...)'
  365 | extern int sprintf (char *__restrict __s,
      |                     ~~~~~~~~~~~~~~~~~^~~
a.cc:8:20: error: 'class std::unordered_set<int>' has no member named 'contains'
    8 |   return !indices->contains(std::string(key)));
      |                    ^~~~~~~~
a.cc:8:46: error: expected ';' before ')' token
    8 |   return !indices->contains(std::string(key)));
      |                                              ^
      |                                              ;
a.cc:8:46: error: expected primary-expression before ')' token
a.cc: At global scope:
a.cc:11:85: error: 'std::vector' has not been declared
   11 | void walk(int cx, int tx, int cy, int ty, std::unordered_set<std::string>* indices, std::vector<std::string>* result) {
      |                                                                                     ^~~
a.cc:11:96: error: expected ',' or '...' before '<' token
   11 | void walk(int cx, int tx, int cy, int ty, std::unordered_set<std::string>* indices, std::vector<std::string>* result) {
      |                                                                                                ^
a.cc: In function 'void walk(int, int, int, int, std::unordered_set<std::__cxx11::basic_string<char> >*, int)':
a.cc:16:35: error: cannot convert 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<int>*'
   16 |     if (check_indices(cx + 1, cy, indices)) {
      |                                   ^~~~~~~
      |                                   |
      |                                   std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:5:59: note:   initializing argument 3 of 'bool check_indices(int, int, std::unordered_set<int>*)'
    5 | bool check_indices(int a, int b, std::unordered_set<int>* indices) {
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:17:7: error: 'result' was not declared in this scope
   17 |       result->push_back("R");
      |       ^~~~~~
a.cc:22:35: error: cannot convert 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<int>*'
   22 |     if (check_indices(cx, cy + 1, indices)) {
      |                                   ^~~~~~~
      |                                   |
      |                                   std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:5:59: note:   initializing argument 3 of 'bool check_indices(int, int, std::unordered_set<int>*)'
    5 | bool check_indices(int a, int b, std::unordered_set<int>* indices) {
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:23:7: error: 'result' was not declared in this scope
   23 |       result->push_back("D");
      |       ^~~~~~
a.cc:28:35: error: cannot convert 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<int>*'
   28 |     if (check_indices(cx - 1, cy, indices)) {
      |                                   ^~~~~~~
      |                                   |
      |                                   std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:5:59: note:   initializing argument 3 of 'bool check_indices(int, int, std::unordered_set<int>*)'
    5 | bool check_indices(int a, int b, std::unordered_set<int>* indices) {
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:29:7: error: 'result' was not declared in this scope
   29 |       result->push_back("L");
      |       ^~~~~~
a.cc:34:25: error: expected ')' before 'cy'
   34 |     if (check_indices(cx cy - 1, indices)) {
      |                      ~  ^~~
      |                         )
a.cc:34:34: error: invalid conversion from 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'int' [-fpermissive]
   34 |     if (check_indices(cx cy - 1, indices)) {
      |                                  ^~~~~~~
      |                                  |
      |                                  std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:34:22: error: too few arguments to function 'bool check_indices(int, int, std::unordered_set<int>*)'
   34 |     if (check_indices(cx cy - 1, indices)) {
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
a.cc:5:6: note: declared here
    5 | bool check_indices(int a, int b, std::unordered_set<int>* indices) {
      |      ^~~~~~~~~~~~~
a.cc:35:7: error: 'result' was not declared in this scope
   35 |       result->push_back("U");
      |       ^~~~~~
a.cc:36:21: error: expected ')' before 'tx'
   36 |       return walk(cx tx, cy - 1, ty, indices, result);
      |                  ~  ^~~
      |                     )
a.cc:40:33: error: cannot convert 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<int>*'
   40 |   if (check_indices(cx + 1, cy, indices)) {
      |                                 ^~~~~~~
      |                                 |
      |                                 std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:5:59: note:   initializing argument 3 of 'bool check_indices(int, int, std::unordered_set<int>*)'
    5 | bool check_indices(int a, int b, std::unordered_set<int>* indices) {
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:41:5: error: 'result' was not declared in this scope
   41 |     result->push_back("R");
      |     ^~~~~~
a.cc:42:19: error: expected ')' before 'tx'
   42 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                ~  ^~~
      |                   )
a.cc:44:33: error: cannot convert 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<int>*'
   44 |   if (check_indices(cx - 1, cy, indices)) {
      |                                 ^~~~~~~
      |                                 |
      |                                 std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:5:59: note:   initializing argument 3 of 'bool check_indices(int, int, std::unordered_set<int>*)'
    5 | bool check_indices(int a, int b, std::unordered_set<int>* indices) {
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:45:5: error: 'result' was not declared in this scope
   45 |     result->push_back("L");
      |     ^~~~~~
a.cc:46:19: error: expected ')' before 'tx'
   46 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                ~  ^~~
      |                   )
a.cc:48:33: error: cannot convert 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<int>*'
   48 |   if (check_indices(cx, cy + 1, indices)) {
      |                                 ^~~~~~~
      |                                 |
      |                                 std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:5:59: note:   initializing argument 3 of 'bool check_indices(int, int, std::unordered_set<int>*)'
    5 | bool check_indices(int a, int b, std::unordered_set<int>* indices) {
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:49:5: error: 'result' was not declared in this scope
   49 |     result->push_back("D");
      |     ^~~~~~
a.cc:50:19: error: expected ')' before 'tx'
   50 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                ~  ^~~
      |                   )
a.cc:52:33: error: cannot convert 'std::unordered_set<std::__cxx11::basic_string<char> >*' to 'std::unordered_set<int>*'
   52 |   if (check_indices(cx, cy - 1, indices)) {
      |                                 ^~~~~~~
      |                                 |
      |                                 std::unordered_set<std::__cxx11::basic_string<char> >*
a.cc:5:59: note:   initializing argument 3 of 'bool check_indices(int, int, std::unordered_set<int>*)'
    5 | bool check_indices(int a, int b, std::unordered_set<int>* indices) {
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:53:5: error: 'result' was not declared in this scope
   53 |     result->push_back("U");
      |     ^~~~~~
a.cc:54:19: error: expected ')' before 'tx'
   54 |     return walk(cx tx, cy - 1, ty, indices, result);
      |                ~  ^~~
      |                   )
a.cc: In function 'int main()':
a.cc:69:8: error: 'vector' is not a member of 'std'
   69 |   std::vector<std::string> result;
      |        ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <algorithm>
  +++ |+#include <vector>
    4 | 
a.cc:69:26: error: expected primary-expression before '>' token
   69 |   std::vector<std::string> result;
      |                          ^
a.cc:69:28: error: 'result' was not declared in this scope
   69 |   std::vector<std::string> result;
      |                            ^~~~~~
a.cc:76:14: error: expected ';' before '&' token
   76 |   for (auto p&: result) {
      |              ^
      |              ;
a.cc:76:15: error: expected primary-expression before ':' token
   76 |   for (auto p&: result) {
      |               ^
a.cc:76:15: error: expected ';' before ':' token
   76 |   for (auto p&: result) {
      |               ^
      |               ;
a.cc:76:15: err