#include #include #include using namespace std; #define INF 999999999 #define REP( i , n ) for(__typeof(n) i=0;i!=(n);++i) typedef pair PI; int length[1000][2], boundary[1000][2], pred[1000][2]; int main() { int N, M; cin >> N >> M; REP(i,N) { int x; boundary[i][0] = -1; REP(j,M) { cin >> x; if(x) { if(boundary[i][0] == -1) boundary[i][0] = j; boundary[i][1] = j; } } } boundary[N][0] = boundary[N][1] = 0; length[N][0] = length[N][1] = 0; for(int i = N-1; i >= 0; --i) { if(boundary[i][0] == -1) { // prázdný řádek length[i][0] = length[i+1][0] + 1; length[i][1] = length[i+1][1] + 1; boundary[i][0] = boundary[i+1][0]; boundary[i][1] = boundary[i+1][1]; pred[i][0] = 0; pred[i][1] = 1; continue; } length[i][0] = length[i][1] = INF; REP(j,2) { int x = boundary[i+1][j]; int d = boundary[i][1] - boundary[i][0]; int left, right; if(x <= boundary[i][0]) { right = boundary[i][1] - x; left = right + d; } else if(x >= boundary[i][1]) { left = x - boundary[i][0]; right = left + d; } else { left = boundary[i][1] - x + d; right = x - boundary[i][0] + d; } left += length[i+1][j] + 1; right += length[i+1][j] + 1; if(left < length[i][0]) { length[i][0] = left; pred[i][0] = j; } if(right < length[i][1]) { length[i][1] = right; pred[i][1] = j; } } } int pos, cnt = 0; if(length[0][1] < length[0][0]) pos = 1; else pos = 0; PI path[1000]; for(int i = 0; i < N; ++i) { if(i) path[cnt++] = PI('U',1); int x = boundary[i+1][pred[i][pos]]; if(x <= boundary[i][0]) { path[cnt++] = PI('R', boundary[i][1] - x); } else if(x >= boundary[i][1]) { path[cnt++] = PI('L', x - boundary[i][0]); } else { int d = boundary[i][1] - boundary[i][0]; if(!pos) { path[cnt++] = PI('L', d); path[cnt++] = PI('R', boundary[i][1] - x); } else { path[cnt++] = PI('R', d); path[cnt++] = PI('L', x - boundary[i][0]); } } } cout << length[0][pos]-1 << endl; while(cnt >= 0) { REP(i, path[cnt].second) cout << path[cnt].first; --cnt; } cout << endl; return 0; }