LoginSignup
0
0

More than 1 year has passed since last update.

AtCoder C - Back and Forth 解法メモ

Posted at

2回目の行きの際にはL、Dは必ず一回発生し、U、Rは1回目よりも値が差分+1大きくなる。
同様に2回目帰りの際にはR,Uが必ず一回発生し、D、Rは1回目よりも値が差分+1大きくなる。

上記には気がつけたが、コーディングに落とし込む能力がなかった。


sx,sy,tx,ty = list(map(int, input().split()))

x = tx - sx # x座標間の差分を出す
y = ty - sy # y座標間の差分を出す
ans = "R"*x + "U"*y + "L"*x + "D"*y # 1回目の行きと帰り
ans += "D" + "R"*(x+1) + "U"*(y+1) + "L" + "U" + "L"*(x+1) + "D"*(y+1) + "R" # 2回目の行きと帰り
print(ans)



参考
https://atcoder.jp/contests/abc051/submissions/27297543

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0