CF1662M.Bottle Arrangements

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Gabriella has been instructed to organize a renowned wine tasting event which will be attended by mm critics. On display, there will be nn different varieties of wine, each of which can either be a red wine or a white wine.

The wines will come in nn bottles arranged in a line on the table, and, for convenience, each critic will sip from a contiguous interval of bottles: that is, he/she will taste exactly the bottles at position a, a+1, …, ba, \, a + 1, \, \dots, \, b for some 1≤a≤b≤n1 \le a \le b \le n. The interval depends on the critic, who will select it on the spot according to their preferences. In fact, the ii-th critic (1≤i≤m1 \le i \le m) has requested that he/she wants to taste exactly rir_i red wines and wiw_i white wines.

Gabriella has yet to choose how many bottles of red wine and white wine there will be, and in what order they will appear. Help her find an arrangement (that is, a sequence of nn bottles of either red or white wine) that satisfies the requests of all the critics, or state that no such arrangement exists.

加布里埃拉受命组织一场著名的品酒会,将有 mm 位品酒师出席。现场将展出 nn 种不同的葡萄酒,每种葡萄酒要么是红葡萄酒,要么是白葡萄酒。

这些葡萄酒将装在 nn 个酒瓶中,并按直线顺序摆放在桌上。为方便起见,每位品酒师将品尝一段连续区间的酒瓶:即他/她将恰好品尝位置为 a, a+1, …, ba, \, a + 1, \, \dots, \, b 的酒瓶,其中 1≤a≤b≤n1 \le a \le b \le n。该区间取决于品酒师本人,并将根据其个人偏好当场选定。事实上,第 ii 位品酒师(1≤i≤m1 \le i \le m)提出要求:他/她希望恰好品尝到 rir_i 瓶红葡萄酒和 wiw_i 瓶白葡萄酒。

加布里埃拉尚未确定红葡萄酒与白葡萄酒各自的瓶数,也未确定它们的排列顺序。请帮助她找出一种满足所有品酒师要求的排列方式(即一个由 nn 个红/白葡萄酒瓶组成的序列),或判定这样的排列不存在。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤1001\le t\le 100) — the number of test cases. The descriptions of the tt test cases follow.

The first line of each test case contains two integers nn and mm (1≤n≤1001 \le n \le 100, 1≤m≤1001 \le m \le 100) — the number of bottles of wine and the number of critics.

Each of the next mm lines contains two integers rir_i and wiw_i (0≤ri, wi≤1000 \le r_i, \, w_i \le 100, ri+wi≥1r_i + w_i \ge 1) — the number of red and white wines that the ii-th critic wants to taste.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001\le t\le 100),表示测试用例的数量。接下来是 tt 个测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤1001 \le n \le 100,1≤m≤1001 \le m \le 100),分别表示红酒瓶数和评论家人数。

接下来的 mm 行中,每行包含两个整数 rir_i 和 wiw_i(0≤ri, wi≤1000 \le r_i, \, w_i \le 100,且 ri+wi≥1r_i + w_i \ge 1),表示第 ii 位评论家希望品尝的红酒和白酒的数量。

输出格式

For each test case, if at least one solution exists, print a string of length nn made up of the characters R and W, where the jj-th character (1≤j≤n1 \le j \le n) denotes the type of the wine in the jj-th bottle of the arrangement (R for red and W for white). If there are multiple solutions, print any.

If no solution exists, print the string IMPOSSIBLE.

对于每个测试用例,如果至少存在一个解,则输出一个长度为 nn 的字符串,该字符串仅由字符 R 和 W 组成,其中第 jj 个字符(1≤j≤n1 \le j \le n)表示排列中第 jj 个酒瓶中所装葡萄酒的类型(R 表示红葡萄酒,W 表示白葡萄酒)。若存在多个解,输出任意一个即可。

若不存在解,则输出字符串 IMPOSSIBLE。

输入输出样例

  • 输入#1

    3
    5 3
    1 0
    3 2
    2 2
    4 3
    2 1
    1 1
    0 3
    3 2
    0 2
    0 3

    输出#1

    RWRRW
    IMPOSSIBLE
    WWW

说明/提示

In the first test case, there are n=5n = 5 bottles of wine to be arranged and m=3m = 3 critics. The arrangement RWRRW satisfies the requests of all three critics. Indeed:

  • the first critic can choose the interval [3, 3][3, \, 3], which contains exactly one bottle of red wine (note that [1, 1][1, \, 1] and [4, 4][4, \, 4] are other valid choices);
  • the second critic can choose the interval [1, 5][1, \, 5], which contains 33 bottles of red wine and 22 bottles of white wine;
  • the third critic can choose the interval [2, 5][2, \, 5], which contains 22 bottles of red wine and 22 bottles of white wine.

在第一个测试用例中,有 n=5n = 5 瓶葡萄酒需要排列,以及 m=3m = 3 位品酒师。排列 RWRRW 满足所有三位品酒师的要求。事实上:

  • 第一位品酒师可以选择区间 [3, 3][3, \, 3],该区间恰好包含一瓶红葡萄酒(注意:[1, 1][1, \, 1] 和 [4, 4][4, \, 4] 也是其他可行的选择);
  • 第二位品酒师可以选择区间 [1, 5][1, \, 5],该区间包含 33 瓶红葡萄酒和 22 瓶白葡萄酒;
  • 第三位品酒师可以选择区间 [2, 5][2, \, 5],该区间包含 22 瓶红葡萄酒和 22 瓶白葡萄酒。

输入解题思路,AI测评打分。不知道怎么写?

首页