Language: C++

dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

int sx, sy, tx, ty;
vector<vector<int>> visited(2010, vector<int>(2010, -1));
vector<pair<int, int>> goals;
int goal_idx = 1;
queue<pair<int, int>> pos_queue;

string ans(){
    string ans_str = "";
    int x = goals[goal_idx].first, y = goals[goal_idx].second;

    while(x != goals[goal_idx-1].first || y != goals[goal_idx-1].second){
        int min_val = 9999999, min_val_dir = -1;
        for(int i = 0; i < 4; ++ i){
            int mx = x + dx[i], my = y + dy[i];
            if(0 <= mx && mx <= 2002 && 0 <= my && my <= 2002 && 0 <= visited[my][mx] && visited[my][mx] < min_val){
                min_val = visited[my][mx];
                min_val_dir = i;
            }
        }
        x += dx[min_val_dir];
        y += dy[min_val_dir];
        visited[y][x] = 9999999;
        ans_str += ("ULDR"[min_val_dir]);
    }

    rep(i, 2010){
        rep(j, 2010){
            if(visited[i][j] != 9999999) visited[i][j] = -1;
        }
    }
    return ans_str;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> sx >> sy >> tx >> ty;
    sx += 1001;
    sy += 1001;
    tx += 1001;
    ty += 1001;
    goals.emplace_back(sx, sy);
    goals.emplace_back(tx, ty);
    goals.emplace_back(sx, sy);
    goals.emplace_back(tx, ty);
    goals.emplace_back(sx, sy);
    visited[sy][sx] = 0;
    pos_queue.emplace(sx, sy);

    while(goal_idx < 5){
        int x = pos_queue.front().first, y = pos_queue.front().second;
        pos_queue.pop();

        if(x == goals[goal_idx].first && y == goals[goal_idx].second){
            cout << ans();
            visited[goals[goal_idx].second][goals[goal_idx].first] = 0;
            visited[goals[min(4, goal_idx + 1)].second][goals[min(4, goal_idx + 1)].first] = -1;
            queue<pair<int, int>> emp;
            pos_queue = emp;
            pos_queue.emplace(goals[goal_idx].first, goals[goal_idx].second);
            ++ goal_idx;
            continue;
        }

        for(int i = 0; i < 4; ++ i){
            int mx = x + dx[i], my = y + dy[i];
            if(0 <= mx && mx <= 2002 && 0 <= my && my <= 2002 && visited[my][mx] == -1){
                visited[my][mx] = visited[y][x] + 1;
                pos_queue.push(make_pair(mx, my));
            }
        }
    }

    cout << endl;
}

Compiler output:
a.cc:1:1: error: 'dx' does not name a type
    1 | dx[] = {0, 1, 0, -1};
      | ^~
a.cc:6:1: error: 'vector' does not name a type
    6 | vector<vector<int>> visited(2010, vector<int>(2010, -1));
      | ^~~~~~
a.cc:7:1: error: 'vector' does not name a type
    7 | vector<pair<int, int>> goals;
      | ^~~~~~
a.cc:9:1: error: 'queue' does not name a type
    9 | queue<pair<int, int>> pos_queue;
      | ^~~~~
a.cc:11:1: error: 'string' does not name a type
   11 | string ans(){
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:39:5: error: 'cin' was not declared in this scope
   39 |     cin.tie(0);
      |     ^~~
a.cc:40:5: error: 'ios' has not been declared
   40 |     ios::sync_with_stdio(false);
      |     ^~~
a.cc:47:5: error: 'goals' was not declared in this scope
   47 |     goals.emplace_back(sx, sy);
      |     ^~~~~
a.cc:52:5: error: 'visited' was not declared in this scope
   52 |     visited[sy][sx] = 0;
      |     ^~~~~~~
a.cc:53:5: error: 'pos_queue' was not declared in this scope
   53 |     pos_queue.emplace(sx, sy);
      |     ^~~~~~~~~
a.cc:59:42: error: 'y' was not declared in this scope
   59 |         if(x == goals[goal_idx].first && y == goals[goal_idx].second){
      |                                          ^
a.cc:60:13: error: 'cout' was not declared in this scope
   60 |             cout << ans();
      |             ^~~~
a.cc:60:21: error: 'ans' was not declared in this scope
   60 |             cout << ans();
      |                     ^~~
a.cc:62:27: error: 'min' was not declared in this scope; did you mean 'main'?
   62 |             visited[goals[min(4, goal_idx + 1)].second][goals[min(4, goal_idx + 1)].first] = -1;
      |                           ^~~
      |                           main
a.cc:63:13: error: 'queue' was not declared in this scope
   63 |             queue<pair<int, int>> emp;
      |             ^~~~~
a.cc:63:19: error: 'pair' was not declared in this scope
   63 |             queue<pair<int, int>> emp;
      |                   ^~~~
a.cc:63:24: error: expected primary-expression before 'int'
   63 |             queue<pair<int, int>> emp;
      |                        ^~~
a.cc:64:25: error: 'emp' was not declared in this scope
   64 |             pos_queue = emp;
      |                         ^~~
a.cc:71:26: error: 'dx' was not declared in this scope; did you mean 'mx'?
   71 |             int mx = x + dx[i], my = y + dy[i];
      |                          ^~
      |                          mx
a.cc:72:46: error: 'my' was not declared in this scope; did you mean 'mx'?
   72 |             if(0 <= mx && mx <= 2002 && 0 <= my && my <= 2002 && visited[my][mx] == -1){
      |                                              ^~
      |                                              mx
a.cc:73:43: error: 'y' was not declared in this scope
   73 |                 visited[my][mx] = visited[y][x] + 1;
      |                                           ^
a.cc:74:32: error: 'make_pair' was not declared in this scope
   74 |                 pos_queue.push(make_pair(mx, my));
      |                                ^~~~~~~~~
a.cc:79:5: error: 'cout' was not declared in this scope
   79 |     cout << endl;
      |     ^~~~
a.cc:79:13: error: 'endl' was not declared in this scope
   79 |     cout << endl;
      |             ^~~~