Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var points [5][5][4]bool

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for i := 0; i < 9; i++ {
		y := i/2
		if i%2 == 0 {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][1], points[y][k+1][3] = true, true
				}
			}
		} else {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][2], points[y+1][k][0] = true, true
				}
			}
		}
	}
	x := 1
	y := 0
	dir := 1
	dx := []int{0, 1, 0, -1}
	dy := []int{-1, 0, 1, 0}
	ds := "URDL"
	fmt.Printf("%s", string(ds[dir]))
	for !(x == 0 && y == 0) {
		if points[y][x][(dir+3)%4] {
			dir = (dir+3)%4
		} else if points[y][x][dir] {

		} else if points[y][x][(dir+1)%4] {
			dir = (dir+1)%4
		} else {
			dir = (dir+2)%4
		}
		x += dx[dir]
		y += dy[dir]
		fmt.Printf("%s", string(ds[dir]))
	}
	fmt.Println()
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const int N = 20;

void printMaze(int w, int h, bool M[N][N], int x, int y){
	rep(i,h + h + 1){
		rep(j,w + w + 1){
			if(i == y and j == x) cout << "*";
			else cout << M[i][j];
		}
		cout << endl;
	}
}

void extensionOfMaze(int w, int h, bool M[N][N]){
	string s[N];
	rep(i,N) cin >> s[i];

	rep(i,N) rep(j,N) M[i][j] = 0;
	rep(i,h + h - 1){
		auto it = s[i].begin();
		if(i % 2 == 0){ //横線
			for(int j = 0; j < w + w - 1; j++){
				if(j % 2 == 0) M[i + 1][j + 1] = 1;
				else{
					M[i + 1][j + 1] = *it == '1' ? true : false;
					it++;
				}
			}
		}else{ //縦線
			for(int j = 0; j < w + w; j++){
				if(j % 2 == 1) M[i + 1][j + 1] = 0;
				else{
					M[i + 1][j + 1] = *it == '1' ? true : false;
					it++;
				}
			}
		}
	}
}

const int dy[16] = { 0, 1, 0,-1, 1,-1, 1,-1, 0,-2, 0, 2};
const int dx[16] = { 1, 0,-1, 0, 1, 1,-1,-1, 2, 0,-2, 0};
const char dir[4] = {'R', 'D', 'L', 'U'};

// 右手法
// right[d] := d方向（東から時計回り）を向いているときの優先順序
const int rightHand[4][4] = {
	{1,0,3,2},
	{2,1,0,3},
	{3,2,1,0},
	{0,3,2,1}
};

vector<pair<int,char>> getCommand(bool m[N][N]){
	int y = 0, x = 0;
	m[y + 1][x] = 1;

	int d = 0;
	vector<pair<int,char>> res;
	while(true){
		if(y == 2 and x == 0) break;

		rep(i,4){
			int rh = rightHand[d][i];

			int ny = y + dy[rh];
			int nx = x + dx[rh];
			if(m[ny][nx] == 0){
				d = rh;
				y = y + dy[rh] * 2;
				x = x + dx[rh] * 2;

				int nrh = rightHand[d][0];
				int ny = y + dy[nrh];
				int nx = x + dx[nrh];
				if(m[ny][nx] == 0){
					y = y + dy[nrh] * 0;
					x = x + dx[nrh] * 0;
				}
				if(res.empty() or res.back().second != dir[d]) res.emplace_back(make_pair(1, dir[d]));
				else res.back().first++;
				break;
			}else{ 
				if(i == 0) continue;;
				if(res.empty() or res.back().second != dir[rh]) res.emplace_back(make_pair(1, dir[rh]));
				else res.back().first++;

			}
				//break;
		}
		//printMaze(5,5,m,x,y); cout << endl;

	}
	return res;
}

int main(){
	bool m[N][N];
	extensionOfMaze(5, 5, m);
	//printMaze(5, 5, m);
	
	vector<pair<int,char>> tmp = getCommand(m);
	int f = 1;
	for(auto p : tmp){
		//cout << p.first << ' ' << p.second << endl;
		if(p.first == 1) f = 0;
		rep(i,p.first - f){
			cout << p.second;
		}
	}
	cout << endl;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int table[100][100];
string s;

int dx[] = { 0, 1, 0, -1, 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0, -1, 0, 1, 0 };
char c[] = "URDLURDL";

int main(){
	REP(i, 9){
		cin >> s;
		REP(j, s.size()){
			if (i % 2 == 0)	table[i][2 * j + 1] = s[j] - '0';
			else table[i][2 * j] = s[j] - '0';
		}
	}
	bool f = 0;
	string ans = "";
	int x = 0, y = 0, muki = 0;
	while (1){
		cout << x << " " << y << endl;
		if (f&&x == 0 && y == 0)break;
		int ny, nx;
		for (int i = muki; i < muki + 4; i++){
			nx = x + dx[i], ny = y + dy[i];
			if (nx >= 0 && nx <= 8 && ny >= 0 && ny <= 8){
				if (table[ny][nx] == 1){
					x += 2 * dx[i];
					y += 2 * dy[i];
					ans += c[i];
					if (c[i] == 'U')muki = 3;
					else if (c[i] == 'R')muki = 0;
					else if (c[i] == 'D')muki = 1;
					else muki = 2;
					break;
				}
			}
		}
		f = 1;
	}
	cout << ans << endl;
}

C++: #include <iostream>
#include <string>
#define N 10
using namespace std;

int main(){
	string str, ans = "";
	bool h[N][N]; // setinel
	bool v[N][N];
	char dir = 'R';
	int mx = 1;
	int my = 1;
	int i, j, len;
	
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			h[i][j] = v[i][j] = false;
		}
	}

	i = j = 1;
	while(cin >> str){
		if(i == 1) len = str.size();
		if(str.size() == len){
			for (int k = 0; k < str.size(); k++) {
				h[i][k+1] = str[k] == '1' ? true : false;
			}
			i++;
		}else{
			for (int k = 0; k < str.size(); k++) {
				v[j][k+1] = str[k] == '1' ? true : false;
			}
			j++;
		}
	}

	do{
		if (dir == 'L') {
			if(v[my][mx]){
				my++;
				dir = 'D';
			}else if(h[my][mx-1]){
				mx--;
				dir = 'L';
			}else if(v[my-1][mx]){
				my--;
				dir = 'U';
			}else{
				mx++;
				dir = 'R';
			}
		}else if (dir == 'R') {
			if(v[my-1][mx]){
				my--;
				dir = 'U';
			}else if(h[my][mx]){
				mx++;
				dir = 'R';
			}else if(v[my][mx]){
				my++;
				dir = 'D';
			}else{
				mx--;
				dir = 'L';
			}
		}else if (dir == 'U') {
			if(h[my][mx-1]){
				mx--;
				dir = 'L';
			}else if(v[my-1][mx]){
				my--;
				dir = 'U';
			}else if(h[my][mx]){
				mx++;
				dir = 'R';
			}else{
				my++;
				dir = 'D';
			}
		}else if (dir == 'D') {
			if(h[my][mx]){
				mx++;
				dir = 'R';
			}else if(v[my][mx]){
				my++;
				dir = 'D';
			}else if(h[my][mx-1]){
				mx--;
				dir = 'L';
			}else{
				my--;
				dir = 'U';
			}
		}
		ans += dir;
	}while(!(mx == 1 && my == 1));

	cout << ans << endl;

	return 0;
}