import java.awt.Point;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Random;
//B問題
public class Main {
static final long C = 1000000007;
static final int CY = 1000000000;
static final int INF = Integer.MAX_VALUE/2;
StringBuilder sb;
//セット
class Set<F,S> {
F f;
S s;
Set(F f, S s) {this.f = f;this.s = s;}
}
// エサ
static class Car {
public int r, c;
public int tr, tc;
public int i;
public Car(int r, int c, int tr, int tc,int i) {
this.r = r;
this.c = c;
this.tr = tr;
this.tc = tc;
this.i = i;
}
int dist () {
return Math.abs(r -tr) + Math.abs(c- tc);
}
}
int[] a,b,c;
int MA, MB;
static final int S = 30;
static final int K = 450;
static final char U = 'U';
static final char D = 'D';
static final char L = 'L';
static final char R = 'R';
static final int T = 500;
static final char _ = '-';
static final int[][] DIR = new int[][]{{0,-1}, {0,1},{1,0},{-1,0}};
static final char[] DIR_C = new char[]{L, R,D,U};
Random rand = new Random();
//-のことは考えない
public void calc() {
sb = new StringBuilder();
IO sc = new IO();
sc.nextInt();
sc.nextInt();
sc.nextInt();
sc.nextInt();
Car[] cars = new Car[K];
for (int i=0; i < K; i++) {
int a = sc.nextInt()-1;
int b = sc.nextInt()-1;
int c = sc.nextInt()-1;
int d = sc.nextInt()-1;
cars[i] = new Car(a,b,c,d,i);
}
//ゴールが外側にあるやつを前にソート
Arrays.sort(cars,(a,b)-> -(Math.abs(a.tr - 14) + Math.abs(a.tc - 14)) + (Math.abs(b.tr - 14) + Math.abs(b.tc - 14)));
String ans = null;
boolean isBef = false;
for (int ti = 0; ti < T; ti++) {
boolean[][] map = new boolean[S][S];
//t=0
for (int i=0; i < K; i++) {
Car c = cars[i];
map[c.r][c.c] = true;
}
boolean isNone = true;
char[] mes = new char[K];
//移動
for (int i=0; i < K; i++) {
Car c = cars[i];
int[][] dmap = getDistMap(c.tr, c.tc, map);
char ac = _;
int min = dmap[c.r][c.c];
int nt = -1;
for (int t=0; t < 4; t++) {
int dx = c.r + DIR[t][0];
int dy = c.c + DIR[t][1];
if (isIn(dx, dy) && dmap[dx][dy] < min) {
min = dmap[dx][dy];
nt = t;
}
}
if (nt != -1) {
int nr = c.r+ DIR[nt][0], nc = c.c + DIR[nt][1];
if (!map[nr][nc]) {
ac = DIR_C[nt];
map[nr][nc] = true;
c.r = nr;
c.c = nc;
}
}else if ((c.dist() != 0 || ti / 150 %2== 0) && rand.nextDouble() < 0.5){//ランダムに動かす
int nnt = -1;
for (int t=0; t < 4; t++) {
int nr = c.r+ DIR[t][0], nc = c.c + DIR[t][1];
if (isIn(nr, nc) && !map[nr][nc]) {
if (nnt == -1|| rand.nextDouble() < 0.5) {
nnt = t;
}
}
}
if (nnt != -1) {
ac = DIR_C[nnt];
int nr = c.r+ DIR[nnt][0], nc = c.c + DIR[nnt][1];
map[nr][nc] = true;
c.r = nr;
c.c = nc;
}
}
//ゴールに動かす
if (ac == _) {
if (c.c < c.tc) {
int nr = c.r, nc = c.c+1;
if (!map[nr][nc]) {
ac = R;
map[nr][nc] = true;
c.r = nr;
c.c = nc;
}
}else if (c.c > c.tc) {
int nr = c.r, nc = c.c-1;
if (!map[nr][nc]) {
ac = L;
map[nr][nc] = true;
c.r = nr;
c.c = nc;
}
}
}
if (ac == _) {
if (c.r < c.tr) {
int nr = c.r+1, nc = c.c;
if (!map[nr][nc]) {
ac = D;
map[nr][nc] = true;
c.r = nr;
c.c = nc;
}
}else if (c.r > c.tr) {
int nr = c.r-1, nc = c.c;
if (!map[nr][nc]) {
ac = U;
map[nr][nc] = true;
c.r = nr;
c.c = nc;
}
}
}
if (ac != _) isNone = false;
mes[c.i] = ac;
}
if (isNone) {
ans = ti + "\n" + sb;
break;
}
sb.append(mes);
sb.append("\n");
}
if (ans == null) {
ans = T + "\n" + sb;
}
System.out.println(ans);
/*try {
densan.s.game.text.TextIO.writeOutside("out.txt", ans);
} catch (IOException e) {
e.printStackTrace();
}*/
}
static boolean isIn(int x, int y) {
return 0 <= x && x < S && 0 <= y && y < S;
}
public static int[][] getDistMap(int r1, int c1, boolean[][] map) {
int[][] distMap = new int[S][S];
for (int[] i: distMap) {
Arrays.fill(i, INF);
}
//if (map[r1][c1]) return distMap;
ArrayList<Point> list = new ArrayList<Point>();
list.add(new Point(r1,c1));
distMap[r1][c1] = 0;
int index = 1;
//System.err.println("dist");
while (!list.isEmpty()) {
//if (debug) Main.printMap(distMap);
ArrayList<Point> nlist = new ArrayList<Point>();
for (Point p: list) {
//distMap[p.x][p.y] = index;
for (int i=0; i < 4; i++) {
int nr = p.x + DIR[i][0], nc = p.y + DIR[i][1];
if (isIn(nr, nc) && !map[nr][nc]
&&distMap[nr][nc] == INF) {
nlist.add(new Point(nr, nc));
distMap[nr][nc] = index;
}
}
}
//System.err.println();
//後処理
list = nlist;
index++;
}
return distMap;
}
//char型のコピー
public static char[][] copyMap(char[][] map) {
char[][] copy = new char[map.length][];
for (int i=0; i < map.length; i++) {
copy[i] = Arrays.copyOf(map[i], map[i].length);
}
return copy;
}
public static void main(String[] args) {
Main main = new Main();
main.calc();
}
}
class IO extends PrintWriter {
private final InputStream in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
public IO() { this(System.in);}
public IO(InputStream source) { super(System.out); this.in = source;}
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}else{
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
private static boolean isNewLine(int c) { return c == '\n' || c == '\r';}
public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
public boolean hasNextLine() { while(hasNextByte() && isNewLine(buffer[ptr])) ptr++; return hasNextByte();}
public String next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public char[] nextCharArray(int len) {
if (!hasNext()) {
throw new NoSuchElementException();
}
char[] s = new char[len];
int i = 0;
int b = readByte();
while(isPrintableChar(b)) {
if (i == len) {
throw new InputMismatchException();
}
s[i++] = (char) b;
b = readByte();
}
return s;
}
public String nextLine() {
if (!hasNextLine()) {
throw new NoSuchElementException();
}
StringBuilder sb = new StringBuilder();
int b = readByte();
while(!isNewLine(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) {
throw new NoSuchElementException();
}
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b)){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
throw new NumberFormatException();
}
return (int) nl;
}
public char nextChar() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return (char) readByte();
}
public double nextDouble() { return Double.parseDouble(next());}
public int[] nextIntArray(int n) { int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a;}
public long[] nextLongArray(int n) { long[] a = new long[n]; for(int i=0;i<n;i++) a[i] = nextLong(); return a;}
public double[] nextDoubleArray(int n) { double[] a = new double[n]; for(int i=0;i<n;i++) a[i] = nextDouble(); return a;}
public void nextIntArrays(int[]... a) { for(int i=0;i<a[0].length;i++) for(int j=0;j<a.length;j++) a[j][i] = nextInt();}
public int[][] nextIntMatrix(int n,int m) { int[][] a = new int[n][]; for(int i=0;i<n;i++) a[i] = nextIntArray(m); return a;}
public char[][] nextCharMap(int n,int m) { char[][] a = new char[n][]; for(int i=0;i<n;i++) a[i] = nextCharArray(m); return a;}
public void close() { super.close(); try {in.close();} catch (IOException e) {}}
}
./Main.java:51: warning: '_' used as an identifier
static final char _ = '-';
^
(use of '_' as an identifier might not be supported in releases after Java SE 8)
./Main.java:97: warning: '_' used as an identifier
char ac = _;
^
(use of '_' as an identifier might not be supported in releases after Java SE 8)
./Main.java:139: warning: '_' used as an identifier
if (ac == _) {
^
(use of '_' as an identifier might not be supported in releases after Java SE 8)
./Main.java:159: warning: '_' used as an identifier
if (ac == _) {
^
(use of '_' as an identifier might not be supported in releases after Java SE 8)
./Main.java:179: warning: '_' used as an identifier
if (ac != _) isNone = false;
^
(use of '_' as an identifier might not be supported in releases after Java SE 8)
5 warnings