【問題】https://atcoder.jp/contests/abc051/tasks/abc051_c

【方針】1回目の往復は最短経路。2回目は出発の位置から\(+(-1, 0)\)の位置\((A)\)に移動し、ゴールの\(+(0, 1)\)の位置\((B)\)に移動、ゴールに行き、\(+(1, 0)\)の位置\((C)\)に移動、さらに出発の位置から\(+(0, -1)\)の点\((D)\)に戻るという経路を辿れば良い。

【提出コード】
#input
sx, sy, tx, ty = map(int, input().split())
#output
x = tx - sx
y = ty - sy
print("U"*y, "R"*x, "D"*y, "L"*x, "L"*1, "U"*(y+1), "R"*(x+1), "D"*1, "R"*1, "D"*(y+1), "L"*(x+1), "U"*1, sep = "")
【提出結果】https://atcoder.jp/contests/abc051/submissions/26712873
コメント