#include #include using namespace std; // priority: UL, UR, R, LR, LL, L void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { // Print the distance along with the sequence of moves. int currentI = i_start; int currentJ = j_start; bool done = false; int minMoves = 0; string moveStr = ""; // check for impossible solution // not possible if we have the wrong number of rows/col and start in the wrong spot if((abs(i_end-i_start) == n-1 || abs(j_end-j_start) == n-1) && (n-1)%2 != 0) { cout << "Impossible"; } else { while(!done) { // UL, UR if(i_end < currentI) { // L if(j_end < currentJ || j_end == currentJ) { moveStr += "UL"; currentJ -= 1; } // R else { moveStr += "UR"; currentJ += 1; } currentI -= 2; } // R else if(j_end > currentJ) { // R moveStr += "R"; currentJ += 2; } // LR, LL else if(i_end > currentI) { // R if(j_end > currentJ || j_end == currentJ) { // LR moveStr += "LR"; currentJ += 1; } // L else { moveStr += "LL"; currentJ -= 1; } currentI += 2; } // L else if(j_end < currentJ) { // L moveStr += "L"; currentJ -= 2; } moveStr += " "; if(i_end == currentI && j_end == currentJ) done = true; minMoves++; } cout << minMoves << endl; cout << moveStr; //cout << endl << currentI << " " << currentJ << endl << i_end << " " << j_end; } } int main() { int n; cin >> n; int i_start; int j_start; int i_end; int j_end; cin >> i_start >> j_start >> i_end >> j_end; printShortestPath(n, i_start, j_start, i_end, j_end); return 0; }