CF1606D.Red-Blue Matrix

提高+/省选-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a matrix, consisting of nn rows and mm columns. The jj-th cell of the ii-th row contains an integer aija_{ij}.

First, you have to color each row of the matrix either red or blue in such a way that at least one row is colored red and at least one row is colored blue.

Then, you have to choose an integer kk (1≤k<m1 \le k \lt m) and cut the colored matrix in such a way that the first kk columns become a separate matrix (the left matrix) and the last m−km-k columns become a separate matrix (the right matrix).

The coloring and the cut are called perfect if two properties hold:

  • every red cell in the left matrix contains an integer greater than every blue cell in the left matrix;
  • every blue cell in the right matrix contains an integer greater than every red cell in the right matrix.

Find any perfect coloring and cut, or report that there are none.

给你一个由 nn 行和 mm 列组成的矩阵。第 ii 行第 jj 列的单元格中包含一个整数 aija_{ij}。

首先,你需要将矩阵的每一行染成红色或蓝色,使得至少有一行被染成红色,且至少有一行被染成蓝色。

然后,你需要选择一个整数 kk(满足 1≤k<m1 \le k < m),将已染色的矩阵沿列方向切割:前 kk 列构成一个独立的矩阵(左矩阵),后 m−km-k 列构成另一个独立的矩阵(右矩阵)。

若满足以下两个条件,则称该染色方案与切割方式是完美的:

  • 左矩阵中每个红色单元格内的整数均大于左矩阵中每个蓝色单元格内的整数;
  • 右矩阵中每个蓝色单元格内的整数均大于右矩阵中每个红色单元格内的整数。

请找出任意一组完美的染色方案与切割方式;若不存在,则报告无解。

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of testcases.

Then the descriptions of tt testcases follow.

The first line of each testcase contains two integers nn and mm (2≤n,m≤5⋅1052 \le n, m \le 5 \cdot 10^5; n⋅m≤106n \cdot m \le 10^6) — the number of rows and the number of columns in the matrix, respectively.

The ii-th of the next nn lines contains mm integers ai1,ai2,…,aima_{i1}, a_{i2}, \dots, a_{im} (1≤aij≤1061 \le a_{ij} \le 10^6).

The sum of n⋅mn \cdot m over all testcases doesn't exceed 10610^6.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 表示测试用例的数量。

接下来是 tt 个测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n,m≤5⋅1052 \le n, m \le 5 \cdot 10^5;n⋅m≤106n \cdot m \le 10^6)—— 分别表示矩阵的行数和列数。

接下来的 nn 行中,第 ii 行包含 mm 个整数 ai1,ai2,…,aima_{i1}, a_{i2}, \dots, a_{im}(1≤aij≤1061 \le a_{ij} \le 10^6)。

所有测试用例中 n⋅mn \cdot m 的总和不超过 10610^6。

输出格式

For each testcase print an answer. If there are no perfect colorings and cuts in the matrix, then print "NO".

Otherwise, first, print "YES". Then a string, consisting of nn characters: the ii-th character should be 'R' if the ii-th row is colored red and 'B' if it's colored blue. The string should contain at least one 'R' and at least one 'B'. Finally, print an integer kk (1≤k<m1 \le k \lt m) — the number of columns from the left that are cut.

对每个测试用例输出一个答案。如果矩阵中不存在完美的着色方案和分割方式,则输出 "NO"。

否则,首先输出 "YES"。然后输出一个长度为 nn 的字符串:第 ii 个字符应为 'R'(表示第 ii 行被染成红色)或 'B'(表示第 ii 行被染成蓝色)。该字符串中必须至少包含一个 'R' 和至少一个 'B'。最后,输出一个整数 kk(1≤k<m1 \le k \lt m)—— 表示从左侧起被分割的列数。

输入输出样例

  • 输入#1

    3
    5 5
    1 5 8 8 7
    5 2 1 4 3
    1 6 9 7 5
    9 3 3 3 2
    1 7 9 9 8
    3 3
    8 9 8
    1 5 3
    7 5 7
    2 6
    3 3 3 2 2 2
    1 1 1 4 4 4

    输出#1

    YES
    BRBRB 1
    NO
    YES
    RB 3

说明/提示

The coloring and the cut for the first testcase:

第一个测试用例的染色方案与割集:

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

首页