Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@recuraki

Codeforces Round #615 B. Collecting Packages

More than 1 year has passed since last update.

シンプルな問題

概要

  • x,yの二次元平面があり、たかだかマスは1000程度である
  • 0,0にロボットがおり、UかRのアクションを行える
  • 100個のnx, nyが順番に与えられる
  • ロボットは各nx,nyを通過できるか判定せよ。YESの場合、例を1つ表示せよ。

アプローチ

  • 今の座標をx,yに対して、x <= nx かつ y <= nyであるかを判定。NGなら、"NO"が確定
  • 可能なら、x軸の差分だけRを、y軸の差分だけUを表示する
q = int(input())
for q in range(q):
    qq = int(input())
    dat = []
    s = ""
    for _ in range(qq):
        x, y = map(int, input().split())
        dat.append([x, y])
        dat.sort(key=lambda a: a[0] + a[1])
    cx, cy = 0, 0
    f = True
    for i in range(qq):
        x, y = dat[i][0], dat[i][1]
        if x < cx or y < cy:
            f = False
            break
        s += "R" * (x - cx)
        s += "U" * (y - cy)
        cx,cy = dat[i][0], dat[i][1]
    if f:
        print("YES")
        print(s)
    else:
        print("NO")

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
recuraki
AtCoder(水), Codeforces(青), TopCoder(青)をうろうろ (技術士/CCIE/CISSP/CISM/CISA/一陸技/線路/伝送)

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?