Problem:


Score : 300 points

Problem Statement

Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.

Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.

Here, both the x- and y-coordinates before and after each movement must be integers.

He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).

Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).

Under this condition, find a shortest path for him.  

Constraints

-1000 ≤ sx < tx ≤ 1000 

-1000 ≤ sy < ty ≤ 1000 

sx,sy,tx and ty are integers.

Input

The input is given from Standard Input in the following format:

sx sy tx ty

Output

Print a string S that represents a shortest path for Dolphin.

The i-th character in S should correspond to his i-th movement.

The directions of the movements should be indicated by the following characters:  

U: Up

D: Down

L: Left

R: Right

If there exist multiple shortest paths under the condition, print any of them.

Sample Input 1

0 0 1 2

Sample Output 1

UURDDLLUUURRDRDDDLLU

One possible shortest path is:

Going from (sx,sy) to (tx,ty) for the first time: (0,0) → (0,1) → (0,2) → (1,2)

Going from (tx,ty) to (sx,sy) for the first time: (1,2) → (1,1) → (1,0) → (0,0)

Going from (sx,sy) to (tx,ty) for the second time: (0,0) → (-1,0) → (-1,1) → (-1,2) → (-1,3) → (0,3) → (1,3) → (1,2)

Going from (tx,ty) to (sx,sy) for the second time: (1,2) → (2,2) → (2,1) → (2,0) → (2,-1) → (1,-1) → (0,-1) → (0,0)

Sample Input 2

-2 -2 1 1

Sample Output 2

UURRURRDDDLLDLLULUUURRURRDDDLLDL



Sample input:
0 0 1 2


Sample output:
UURDDLLUUURRDRDDDLLU

Submission status: Time Limit Exceeded

Solution code:
sx, sy, tx, ty = map(int, input().split())
visited = [[0] * 4001 for _ in range(4001)]
ofs = 2000

stoij = {'U':[0, 1], 'D':[0,-1], 'L':[-1, 0], 'R':[1, 0]}

from collections import deque
def bfs(si, sj, gi, gj):
    q = deque([[si, sj, '']])
    visitedinbfs = [[0] * 4001 for _ in range(4001)]
    visitedinbfs[sj+ofs][si+ofs] = 1

    while q:
        i, j, s = q.popleft()
        if i == gi and j == gj:
            break

        for ns in ['U', 'D', 'L', 'R']:
            mi, mj = stoij[ns]
            ni, nj = i + mi, j + mj
            if visitedinbfs[nj+ofs][ni+ofs] == 1 or visited[nj+ofs][ni+ofs] == 1:
                continue
            visitedinbfs[nj+ofs][ni+ofs] = 1
            q.append([ni, nj, s+ns])

    for ss in s:
        mi, mj = stoij[ss]
        si += mi
        sj += mj
        if si == gi and sj == gj:
            break
        visited[sj+ofs][si+ofs] = 1
    
    return s

ans = bfs(sx, sy, tx, ty)
ans += bfs(tx, ty, sx, sy)
ans += bfs(sx, sy, tx, ty)
ans += bfs(tx, ty, sx, sy)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from collections import defaultdict, deque
Dirc = ('U', 'D', 'R', 'L')
Dirc2 = ('D', 'U', 'L', 'R')
dircn = ((1, 0), (-1, 0), (0, 1), (0, -1))
blocked = defaultdict(int)
sx, sy, tx, ty = mapint()

ans = []
for i in range(4):
    queue = deque([(sx, sy, [])])
    checked = defaultdict(int)
    dirc = Dirc if i%2==0 else Dirc2
    while queue:
        x, y, lis = queue.popleft()
        lis = lis[:]
        flg = 0
        for d, (dy, dx) in zip(dirc, dircn):
            nx, ny = x+dx, y+dy
            if checked[(nx, ny)] or blocked[(nx, ny)]:
                continue
            if nx==sx and ny==sy:
                continue
            if nx==tx and ny==ty:
                flg = 1
                lis.append(d)
                break
            queue.append((nx, ny, lis+[d]))
            checked[(nx, ny)] = 1
        if flg:
            x, y = sx, sy
            for s in lis[:-1]:
                dy, dx = dircn[dirc.index(s)]
                x += dx
                y += dy
                blocked[(x, y)] = 1
            if i%2==0:
                lis = list(reversed(lis))
            ans.extend(lis)
            break
print(''.join(ans))

Submission status: Time Limit Exceeded

Solution code:
import queue
from collections import defaultdict

Sx, Sy, Tx, Ty = map(int, input().rstrip().split())

d = defaultdict(lambda: None)
keys = []
for _ in range(4):

    q = queue.Queue()
    q.put((Sx, Sy, Sx, Sy))
    tx, ty = Tx, Ty
    while True:
        sx, sy, cx, cy = q.get()
        
        if sx == tx and sy == ty:
            break
        
        for dx, dy in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
            k = '{}_{}'.format(sx+dx, sy+dy)
            if k not in d.keys():
                d[k] = (sx, sy)
                q.put((sx+dx, sy+dy, sx, sy))
    
    sx, sy = Sx, Sy
    cx, cy = tx, ty
    move = []
    while True:
        if cx == sx and cy == sy:
            break
        
        k = '{}_{}'.format(cx, cy)
        if not (cx == Sx and cy == Sy) and not (cx == Tx and cy == Ty):
            keys.append(k)
        
        new_cx, new_cy = d[k]
    
        dx = cx - new_cx
        dy = cy - new_cy
        dict_move = {'1_0': 'R', '-1_0': 'L', '0_1': 'U', '0_-1': 'D'}
        move.append(dict_move['{}_{}'.format(dx, dy)])
        
        cx, cy = new_cx, new_cy
        
    print(''.join(move[::-1]), end='')
    
    Sx, Sy, Tx, Ty = Tx, Ty, Sx, Sy
    
    d = defaultdict(lambda: None)
    for k in keys:
        d[k] = None

Submission status: Time Limit Exceeded

Solution code:
sx, sy, tx, ty = map(int, input().split())
gp = []


def fn(q, gx, gy):
    while len(q) > 0:
        x, y, d, p = q.pop(0)
        for xx, yy, dd in [(x + 1, y, 'R'), (x - 1, y, 'L'), (x, y + 1, 'U'), (x, y - 1, 'D')]:
            if (xx, yy) == (gx, gy):
                gp.extend(p + [(xx, yy)])
                return d + dd
            if -1000 <= xx <= 1000 and -1000 <= yy <= 1000 and (xx, yy) not in p:
                q.append((xx, yy, d + dd, p + [(xx, yy)]))


print(fn([(sx, sy, '', gp)], tx, ty) + fn([(tx, ty, '', gp)], sx, sy) +
      fn([(sx, sy, '', gp)], tx, ty) + fn([(tx, ty, '', gp)], sx, sy))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from pprint import pprint
import sys
import copy
sys.setrecursionlimit(10**7)
def MI(): return map(int, sys.stdin.readline().split())


def bfs(q, sy, sx, ty, tx):
    visited[sy][sx] = 1
    while len(q) != 0:
        y, x, street, ans = q.popleft()
        # print(street)
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            route = copy.copy(street)
            if 0 <= ny <= h-1 and 0 <= nx <= w-1 and visited[ny][nx] == 0:
                require[ny][nx] = require[y][x] + 1
                visited[ny][nx] = 1
                route.append([ny, nx])
                q.append([ny, nx, route, ans+direction[i]])
                if ny == ty and nx == tx:  # 探索終了
                    # pprint(require)
                    # pprint(visited)
                    # pprint(route)
                    y, x, route, ans = q.pop()
                    # pprint(ans)
                    return [route,ans]


sx, sy, tx, ty = MI()
sx += 1000
sy += 1000
tx += 1000
ty += 1000
h = 3000
w = 3000
maze = [[0] * w for _ in range(h)]
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
direction = ['L', 'U', 'R', 'D']


visited = [[0] * w for _ in range(h)]
require = [[0] * w for _ in range(h)]
que = deque()
que.append([sy, sx, [], ''])
route, ans = bfs(que, sy, sx, ty, tx)
# print(route)
# print(ans)


visited = [[0] * w for _ in range(h)]
require = [[0] * w for _ in range(h)]
for y, x in route:
    visited[y][x] = 1
visited[sy][sx] = visited[ty][tx] = 0

que.clear()
que.append([ty, tx, route, ans])
route, ans = bfs(que, ty, tx, sy, sx)
# print(route)
# print(ans)


visited = [[0] * w for _ in range(h)]
require = [[0] * w for _ in range(h)]
for y, x in route:
    visited[y][x] = 1
visited[sy][sx] = 0
visited[ty][tx] = 0

# pprint(visited)
que.clear()
que.append([sy, sx, route, ans])
route, ans = bfs(que, sy, sx, ty, tx)
# print(route)
# print(ans)


visited = [[0] * w for _ in range(h)]
require = [[0] * w for _ in range(h)]
for y, x in route:
    visited[y][x] = 1
visited[sy][sx] = 0
visited[ty][tx] = 0

que.clear()
que.append([ty, tx, route, ans])
route, ans = bfs(que, ty, tx, sy, sx)
# print(route)
print(ans)


visited = [[0] * w for _ in range(h)]
require = [[0] * w for _ in range(h)]
for y, x in route:
    visited[y][x] = 1
visited[sy][sx] = 0
visited[ty][tx] = 0
# pprint(visited)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
sx,sy,tx,ty = map(int,input().split())
ans_list = []
(tx,ty) = (tx-sx,ty-sy); (sx,sy) = (0,0)
H,W = ty+3,tx+3
visited = [[0]*(tx+3) for i in range(ty+3)]
d = [[1,0],[0,1],[-1,0],[0,-1]]
(sx,sy) = (sx+1,sy+1); (tx,ty) = (tx+1,ty+1)
def bfs(si,sj,gi,gj):
    tr = [[si,sj]]
    q = deque([[si,sj,tr]])
    while q:
        i,j,tr = q.popleft()
        if (i,j) == (gi,gj):
            return tr
        for di,dj in d:
            ni = i + di; nj = j + dj
            if 0 <= ni <= H-1 and 0 <= nj <= W-1 and visited[ni][nj] == 0:
                visited[ni][nj] = 1
                ntr = tr[:]; ntr.append([ni,nj])
                q.append([ni,nj,ntr])

def change(tr):
    def func(d):
        if d == (1,0):return "U"
        if d == (-1,0):return "D"
        if d == (0,-1):return "L"
        if d == (0,1):return "R"
    for i in range(len(tr)-1):
        (ni,nj) = (tr[i+1][0],tr[i+1][1])
        (i,j) = (tr[i][0],tr[i][1])
        d = (ni-i,nj-j)
        ans_list.append(func(d))

tr = []
for cnt in range(2):
    res = bfs(sy,sx,ty,tx)
    for k in range(1,len(res)):
        i,j = res[k][0],res[k][1]
        rei, rej = ty + sx - i, tx + sy - j
        res.append([rei,rej])
    if cnt == 0:
        tr += res
    else:
        tr += res[1:]
    visited = [[0]*W for i in range(H)]
    for i,j in tr:
        visited[i][j] = 1
    visited[ty][tx] = 0

change(tr)
ans = "".join(ans_list)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
sx,sy,tx,ty = map(int,input().split())
ans_list = []
(tx,ty) = (tx-sx,ty-sy); (sx,sy) = (0,0)
H,W = ty+3,tx+3
visited = [[0]*(tx+3) for i in range(ty+3)]
d = [[1,0],[0,1],[-1,0],[0,-1]]
(sx,sy) = (sx+1,sy+1); (tx,ty) = (tx+1,ty+1)
def bfs(si,sj,gi,gj):
    tr = [[si,sj]]
    q = deque([[si,sj,tr]])
    while q:
        i,j,tr = q.popleft()
        if (i,j) == (gi,gj):
            return tr
        for di,dj in d:
            ni = i + di; nj = j + dj
            if 0 <= ni <= H-1 and 0 <= nj <= W-1 and visited[ni][nj] == 0:
                visited[ni][nj] = 1
                ntr = tr[:]; ntr.append([ni,nj])
                q.append([ni,nj,ntr])

def change(tr):
    def func(d):
        if d == (1,0):return "U"
        if d == (-1,0):return "D"
        if d == (0,-1):return "L"
        if d == (0,1):return "R"
    for i in range(len(tr)-1):
        (ni,nj) = (tr[i+1][0],tr[i+1][1])
        (i,j) = (tr[i][0],tr[i][1])
        d = (ni-i,nj-j)
        ans_list.append(func(d))

res = []
for i in range(4):
    if i == 0:
        res += bfs(sy,sx,ty,tx)
    else:
        res = res[:-1] + bfs(sy,sx,ty,tx)
    visited = [[0]*W for i in range(H)]
    for i,j in res:
        visited[i][j] = 1
    sy,ty = ty,sy; sx,tx = tx,sx
    visited[ty][tx] = 0

change(res)
ans = "".join(ans_list)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict
from heapq import *

sx, sy, tx, ty = map(int, sys.stdin.readline().split())
nodeset = set()
excludes = set()

for x in range(sx - 2, tx + 2):
    for y in range(sy - 2, ty + 2):
        nodeset.add((x, y))

def dijkstra(t, f):
    cache = {}
    def get_edges(p):
        if p not in nodeset:
            return []
        ret = cache.get(p, None)
        if ret is not None:
            return ret
        nodes = [
            (p[0], p[1] + 1),
            (p[0], p[1] - 1),
            (p[0] + 1, p[1]),
            (p[0] - 1, p[1])]
        ret = [n for n in nodes if n not in excludes]
        cache[p] = ret
        return ret

    q, seen, mins = [(0, f, ())], set(), {f: 0}
    while q:
        (cost, v1, path) = heappop(q)
        if v1 not in seen:
            seen.add(v1)
            path = (v1,) + path
            if v1 == t:
                return path
            for v2 in get_edges(v1):
                if v2 in seen: continue
                prev = mins.get(v2, None)
                next = cost + 1
                if prev is None or next < prev:
                    mins[v2] = next
                    heappush(q, (next, v2, path))
    return float("inf")


p0 = (sx, sy)
p1 = (tx, ty)

def add_exclude_points(path):
    for p in path[1:-1]:
        excludes.add(p)

def path2str(path):
    prev = path[0]
    ret = ''
    for p in path[1:]:
        d = (p[0] - prev[0]), (p[1] - prev[1])
        if d == (0, 1):
            ret += 'U'
        elif d == (0, -1):
            ret += 'D'
        elif d == (1, 0):
            ret += 'R'
        elif d == (-1, 0):
            ret += 'L'
        else:
            raise 'BUG'
        prev = p
    return ret

ret = ''
for _ in range(2):
    path = dijkstra(p0, p1)
    # print(path)
    add_exclude_points(path)
    ret += path2str(path)
    path = dijkstra(p1, p0)
    # print(path)
    add_exclude_points(path)
    ret += path2str(path)

print(ret)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict
from heapq import *

sx, sy, tx, ty = map(int, sys.stdin.readline().split())
excludes = set()

def dijkstra(t, f):
    cache = {}
    def get_edges(p):
        ret = cache.get(p, None)
        if ret is not None:
            return ret
        nodes = [
            (p[0], p[1] + 1),
            (p[0], p[1] - 1),
            (p[0] + 1, p[1]),
            (p[0] - 1, p[1])]
        ret = [n for n in nodes if n not in excludes]
        cache[p] = ret
        return ret

    q, seen, mins = [(0, f, ())], set(), {f: 0}
    while q:
        (cost, v1, path) = heappop(q)
        if v1 not in seen:
            seen.add(v1)
            path = (v1,) + path
            if v1 == t:
                return path
            for v2 in get_edges(v1):
                if v2 in seen: continue
                prev = mins.get(v2, None)
                next = cost + 1
                if prev is None or next < prev:
                    mins[v2] = next
                    heappush(q, (next, v2, path))
    return float("inf")


p0 = (sx, sy)
p1 = (tx, ty)

def add_exclude_points(path):
    for p in path[1:-1]:
        excludes.add(p)

def path2str(path):
    prev = path[0]
    ret = ''
    for p in path[1:]:
        d = (p[0] - prev[0]), (p[1] - prev[1])
        if d == (0, 1):
            ret += 'U'
        elif d == (0, -1):
            ret += 'D'
        elif d == (1, 0):
            ret += 'R'
        elif d == (-1, 0):
            ret += 'L'
        else:
            raise 'BUG'
        prev = p
    return ret

ret = ''
for _ in range(2):
    path = dijkstra(p0, p1)
    # print(path)
    add_exclude_points(path)
    ret += path2str(path)
    path = dijkstra(p1, p0)
    # print(path)
    add_exclude_points(path)
    ret += path2str(path)
print(ret)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict
from heapq import *

sx, sy, tx, ty = map(int, sys.stdin.readline().split())
excludes = set()

def dijkstra(t, f):
    def get_edges(p):
        nodes = [
            (p[0], p[1] + 1),
            (p[0], p[1] - 1),
            (p[0] + 1, p[1]),
            (p[0] - 1, p[1])]
        return [n for n in nodes if n not in excludes]

    q, seen, mins = [(0, f, [])], set(), {f: 0}
    while q:
        (cost, v1, path) = heappop(q)
        if v1 not in seen:
            seen.add(v1)
            path = [v1] + path
            if v1 == t:
                return path

            for v2 in get_edges(v1):
                if v2 in seen: continue
                prev = mins.get(v2, None)
                next = cost + 1
                if prev is None or next < prev:
                    mins[v2] = next
                    heappush(q, (next, v2, path))
    return float("inf")


p0 = (sx, sy)
p1 = (tx, ty)

def add_exclude_points(path):
    for p in path[1:-1]:
        excludes.add(p)

def path2str(path):
    prev = path[0]
    ret = ''
    for p in path[1:]:
        d = (p[0] - prev[0]), (p[1] - prev[1])
        if d == (0, 1):
            ret += 'U'
        elif d == (0, -1):
            ret += 'D'
        elif d == (1, 0):
            ret += 'R'
        elif d == (-1, 0):
            ret += 'L'
        else:
            raise 'BUG'
        prev = p
    return ret

ret = ''
for _ in range(2):
    path = dijkstra(p0, p1)
    # print(path)
    add_exclude_points(path)
    ret += path2str(path)
    path = dijkstra(p1, p0)
    # print(path)
    add_exclude_points(path)
    ret += path2str(path)
print(ret)

Submission status: Accepted

Solution code:
def main():
    sx, sy, tx, ty = map(int, input().split())
    x = tx - sx
    y = ty - sy
    s = "R"*x + "U"*y
    s += s.translate(str.maketrans({"U": "D",
                                    "D": "U", "L": "R", "R": "L"}))
    tmp = "D" + "R"*(x+1) + "U"*(y+1) + "L"
    s += tmp + tmp.translate(str.maketrans({"U": "D",
                                            "D": "U", "L": "R", "R": "L"}))
    print(s)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    sx, sy, tx, ty = map(int, input().split())
    x = tx - sx
    y = ty - sy
    s = ""
    s += "R"*x
    s += "U"*y
    s += s.translate(str.maketrans({"U": "D",
                                    "D": "U", "L": "R", "R": "L"}))
    tmp = ""
    tmp += "D"
    tmp += "R"*(x+1)
    tmp += "U"*(y+1)
    tmp += "L"
    s += tmp + tmp.translate(str.maketrans({"U": "D",
                                            "D": "U", "L": "R", "R": "L"}))
    print(s)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    sx, sy, tx, ty = map(int, input().split())
    x = tx - sx
    y = ty - sy
    s = ""
    for i in range(2):
        tmp = ""
        if i:
            tmp += "D"
            tmp += "R"*(x+1)
            tmp += "U"*(y+1)
            tmp += "L"

        else:
            tmp += "R"*x
            tmp += "U"*y
        s += tmp + tmp.translate(str.maketrans({"U": "D",
                                                "D": "U", "L": "R", "R": "L"}))
    print(s)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy
print("U"*dy + "R"*dx, end="")
print("D"*dy + "L"*dx, end="")
print("L" + "U"*(dy+1) +"R"*(dx+1) +"D", end="")
print("R" + "D"*(dy+1) +"L"*(dx+1) +"U", end="")

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
x=c-a
y=d-b
print('U'*y+'R'*x+'D'*y+'L'*-~x+'U'*-~y+'R'*-~x+'DR'+'D'*-~y+'L'*-~x+'U')

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
x=tx-sx
y=ty-sy
print('U'*y+'R'*x+'D'*y+'L'*(x+1)+'U'*(y+1)+'R'*(x+1)+'DR'+'D'*(y+1)+'L'*(x+1)+'U')

Submission status: Accepted

Solution code:
sx,sy,tx,ty = map(int,input().split())
ans = ""

ans += "U" * abs(ty-sy)
ans += "R" * abs(tx-sx)
ans += "D" * abs(ty-sy)
ans += "L" * (abs(tx-sx)+1)
ans += "U" * (abs(ty-sy)+1)
ans += "R" * (abs(tx-sx)+1)
ans += "D"
ans += "R"
ans += "D" * (abs(ty-sy)+1)
ans += "L" * (abs(tx-sx)+1)
ans += "U"

print(ans)

Submission status: Accepted

Solution code:
sx,sy,tx,ty = map(int, input().split())

dx = tx - sx
dy = ty - sy

xdir = "R" if dx >= 0 else "L"
xdir_r = "L" if dx >= 0 else "R"
ydir = "U" if dy >= 0 else "D"
ydir_r = "D" if dy >= 0 else "U"

ans = ans_r = ""
ans_2 = ans_2_r = ""
ans += xdir * abs(dx) + ydir * abs(dy)
ans_r += xdir_r * abs(dx) + ydir_r * abs(dy)

ans_2 += ydir_r + xdir * (abs(dx) + 1) + ydir * (abs(dy) + 1) + xdir_r
ans_2_r += ydir + xdir_r * (abs(dx) + 1) + ydir_r * (abs(dy) + 1) + xdir
print(ans + ans_r + ans_2 + ans_2_r)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

dx, dy = tx - sx, ty - sy

first = 'U' * dy + 'R' * dx
second = 'D' * dy + 'L' * dx
third = 'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D'
forth = 'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U'

print(first + second + third + forth)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
ans = []

for i in range(ty-sy):
    ans.append("U")
for i in range(tx-sx):
    ans.append("R")
for i in range(abs(sy-ty)):
    ans.append("D")
for i in range(abs(sx-tx)):
    ans.append("L")

ans.append("L")
for i in range(ty-sy+1):
    ans.append("U")
for i in range(tx-sx+1):
    ans.append("R")
ans.append("D")
ans.append("R")
for i in range(abs(sy-ty)+1):
    ans.append("D")
for i in range(abs(sx-tx)+1):
    ans.append("L")
ans.append("U")
print(*ans, sep='')

Submission status: Accepted

Solution code:
sx,sy,gx,gy = list(map(int,input().split()))
dx,dy=gx-sx,gy-sy
out = []
out.append("R"*dx)
out.append("U"*dy)
out.append("L"*dx)
out.append("D"*dy)
out.append("D")
out.append("R"*(dx+1))
out.append("U"*(dy+1))
out.append("L")
out.append("U")
out.append("L"*(dx+1))
out.append("D"*(dy+1))
out.append("R")
print("".join(out))

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
st1 = "U" * (ty - sy) + "R" * (tx - sx)
ts1 = "D" * (ty - sy) + "L" * (tx - sx)
st2 = "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "D"
ts2 = "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) + "U"

print(st1 + ts1 + st2 + ts2)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
 
ans = ""
 
ans += "U" * (ty - sy) + "R" * (tx - sx)
ans += "D" * (ty - sy) + "L" * (tx - sx)
ans += "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "D"
ans += "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) + "U"
print(ans)

Submission status: Accepted

Solution code:
sx,sy,tx,ty= map(int,input().split())
ans = ''
if sx > tx:
    R = 'L'
    L = 'R'
else:
    R = 'R'
    L = 'L'
if sy > ty:
    U = 'D'
    D = 'U'
else:
    U = 'U'
    D = 'D'
if sx == tx:
    ans += U * (abs(ty-sy))
    ans += L
    ans += D * (abs(ty-sy))
    ans += R * 2
    ans += U * (abs(ty-sy))
    ans += L
    ans += U
    ans += R * 2
    ans += D * (abs(ty-sy)+2)
    ans += L * 2
    ans += U
elif sy == ty:
    ans += R * (abs(tx-sx))
    ans += U
    ans += L * (abs(tx-sx))
    ans += D * 2
    ans += R * (abs(tx-sx))
    ans += U
    ans += R
    ans += D * 2
    ans += L * (abs(tx-sx)+2)
    ans += U * 2
    ans += R
else:
    ans += U * (abs(ty-sy))
    ans += R * (abs(tx-sx))
    ans += U
    ans += L * (abs(tx-sx)+1)
    ans += D * (abs(ty-sy)+1)
    ans += R * (abs(tx-sx)+1)
    ans += U * (abs(ty-sy))
    ans += R
    ans += D * (abs(ty-sy)+1)
    ans += L * (abs(tx-sx)+1)
    ans += U
print(ans)

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
print('U'*(ty-sy)+'R'*(tx-sx)+'D'*(ty-sy)+'L'*(tx-sx)+'L' \
      +'U'*(ty+1-sy)+'R'*(tx+1-sx)+'D'+'R'+'D'*(ty+1-sy) \
      +'L'*(tx+1-sx)+'U')

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
for i in range(sy,ty):
    print('U',end='')
for i in range(sx,tx):
    print('R',end='')
for i in range(sy,ty):
    print('D',end='')
for i in range(sx,tx):
    print('L',end='')
print('L',end='')
for i in range(sy,ty+1):
    print('U',end='')
for i in range(sx,tx+1):
    print('R',end='')
print('D',end='')
print('R',end='')
for i in range(sy,ty+1):
    print('D',end='')
for i in range(sx,tx+1):
    print('L',end='')
print('U',end='')

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())

x=tx-sx
y=ty-sy
ans=[]
for i in range(y):
    ans.append("U")
for i in range(x):
    ans.append("R")
for i in range(y):
    ans.append("D")
for i in range(x+1):
    ans.append("L")
for i in range(y+1):
    ans.append("U")
for i in range(x+1):
    ans.append("R")
ans.append("D")
ans.append("R")
for i in range(y+1):
    ans.append("D")
for i in range(x+1):
    ans.append("L")
ans.append("U")
print("".join(ans))

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
x=tx-sx
y=ty-sy
print('R'*x+'U'*y+'L'*x+'D'*(y+1)+'R'*(x+1)+'U'*(y+1)+'L'+'U'+'L'*(x+1)+'D'*(y+1)+'R')

Submission status: Accepted

Solution code:
sx,sy,tx,ty = map(int,input().split())
a = 'U'*abs(ty-sy)
b = 'R'*abs(tx-sx)
c = 'D'*abs(ty-sy)
d = 'L'*abs(tx-sx)
ans =''
ans += a+b+c+d
ans +='D'
ans +=b+'R'
ans += a + 'U'+'L'
ans += 'U'
ans +=d+'L'
ans += c +'D'+'R'
print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

ans = ""

ans += "U" * (ty - sy) + "R" * (tx - sx)
ans += "D" * (ty - sy) + "L" * (tx - sx)
ans += "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "D"
ans += "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) + "U"
print(ans)

Submission status: Accepted

Solution code:
def main():
    sx, sy, tx, ty = map(int, input().split())
    
    gapx = tx - sx
    gapy = ty - sy
    ans = ""

    #一回目tからsへ
    ans += "U" * gapy
    ans += "R" * gapx
    ans += "D" * gapy
    ans += "L" * gapx

    #二回目
    ans += "L"
    ans += "U" * (gapy + 1)
    ans += "R" * (gapx + 1)
    ans += "D"
    ans += "R"
    ans += "D" * (gapy + 1)
    ans += "L" * (gapx + 1)
    ans += "U"

    print(ans) 


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

ans = []

if tx > sx:
    ans.append('R'*(tx-sx))     #0
    ans.append('L'*(tx-sx))     #2
    ans.append('R'*(tx-sx+1))   #5
    ans.append('L')             #7
    ans.append('L'*(tx-sx+1))   #9
    ans.append('R')             #11
else:
    ans.append('L'*(sx-tx))     #0
    ans.append('R'*(sx-tx))     #2
    ans.append('L'*(sx-tx+1))   #5
    ans.append('R')             #7
    ans.append('R'*(sx-tx+1))   #9
    ans.append('L')             #11

if ty > sy:
    ans.insert(1,'U'*(ty-sy))   #1
    ans.insert(3,'D'*(ty-sy))   #3
    ans.insert(4,'D')           #4
    ans.insert(6,'U'*(ty-sy+1)) #6
    ans.insert(8,'U')           #8
    ans.insert(10,'D'*(ty-sy+1))#10
else:
    ans.insert(1,'D'*(sy-ty))   #1
    ans.insert(3,'U'*(sy-ty))   #3
    ans.insert(4,'U')           #4
    ans.insert(6,'D'*(sy-ty+1)) #6
    ans.insert(8,'D')           #8
    ans.insert(10,'U'*(sy-ty+1))#10

ANS = ''.join(ans)
print(ANS)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

tx_sx = tx - sx
ty_sy = ty - sy


ans = ""
for i in range(ty_sy):
    ans += "U"

for i in range(tx_sx):
    ans += "R"


for i in range(ty_sy):
    ans += "D"

for i in range(tx_sx):
    ans += "L"

ans += "L"

for i in range(ty_sy + 1):
    ans += "U"

for i in range(tx_sx + 1):
    ans += "R"
ans += "DR"

for i in range(ty_sy + 1):
    ans += "D"

for i in range(tx_sx + 1):
    ans += "L"

ans += "U"
print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

dx = tx - sx
dy = ty - sy

route1 = 'R' * dx + 'U' * dy
route2 = 'L' * dx + 'D' * dy
route3 = 'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D'
route4 = 'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U'

ans = route1 + route2 + route3 + route4
print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = list(map(int, input().split(" ")))

dx = tx - sx
dy = ty - sy
ans = 'R'*dx + 'U'*dy 
ans += 'L'*dx + 'D'*dy 
ans += 'L' + 'U'*(dy+1) + 'R'*(dx+1) + 'D'
ans += 'R' + 'D'*(dy+1) + 'L'*(dx+1) + 'U'

print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    sx, sy, tx, ty = LI()
    tx -= sx
    ty -= sy
    x = abs(tx)
    y = abs(ty)
    r,l,u,d = "r","l","u","d"
    ans = ""

    if tx != 0 and ty != 0:
        ans = r*x+u*y+l*x+d*(y+1)+r*(x+1)+u*(y+1)+l+u+l*(x+1)+d*(y+1)+r

        if tx<0:
            ans = ans.replace(r, "L")
            ans = ans.replace(l, "R")
        if ty<0:
            ans = ans.replace(u,"D")
            ans = ans.replace(d,"U")
            
        ans = ans.upper()
        
    else:
        x = max(x,y)
        ans = r*x+u+l*x+d*2+r*x+u+r+u*2+l*(x+2)+d*2+r

        if ty>0:
            ans = ans.replace(r,"U").replace(l,"D").replace(u,"L").replace(d,"R")
        elif tx<0:
            ans = ans.replace(r,"L").replace(l,"R")
        elif ty<0:
            ans = ans.replace(r,"D").replace(l,"U").replace(u,"R").replace(d,"L")
        ans = ans.upper()

    print(ans)
main()

Submission status: Accepted

Solution code:
sx,sy,tx,ty = map(int,input().split())
ans = ""
y = ty-sy
x = tx-sx
ans += "U"*y+"R"*x+"D"*y+"L"*(x+1)+"U"*(y+1)+"R"*(x+1)+"DR"+"D"*(y+1)+"L"*(x+1)+"U"
print(ans)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    sx, sy, tx, ty = LI()

    dx = tx - sx
    dy = ty - sy
    ans_f0 = 'U' * dy + 'R' * dx
    ans_b0 = 'D' * dy + 'L' * dx
    ans_f1 = 'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D'
    ans_b1 = 'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U'

    print(ans_f0 + ans_b0 + ans_f1 + ans_b1)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    sx,sy,ex,ey = i_map()

    fp = "U"*(ey-sy)
    fr = "R"*(ex-sx)
    fd = "D"*(ey-sy)
    fl = "L"*(ex-sx)
    f = fp+fr+fd+fl

    fl = "L"
    sp = "U"*(ey-sy+1)
    fr = "R"*(ex-sx+1)
    fd = "D"
    sr = "R"
    sd = "D"*(ey-sy+1)
    sl = "L"*(ex-sx+1)
    p = "U"
    s = fl+sp+fr+fd+sr+sd+sl+p

    print(f+s)











if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    sx, sy, tx, ty = input_int_list()
    dx, dy = tx - sx, ty - sy
    ans = "R" * dx + "U" * dy + "L" * dx + "D" * dy + "L" + "U" * (dy + 1) + "R" * (dx + 1) + "DR" + "D" * (dy + 1) + "L" * (dx + 1) + "U"
    print(ans)
    return


if __name__ == "__main__":
    main()