CF1761C.Set Construction

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a binary matrix bb (all elements of the matrix are 00 or 11) of nn rows and nn columns.

You need to construct a nn sets A1,A2,,AnA_1, A_2, \ldots, A_n, for which the following conditions are satisfied:

  • Each set is nonempty and consists of distinct integers between 11 and nn inclusive.
  • All sets are distinct.
  • For all pairs (i,j)(i,j) satisfying 1i,jn1\leq i, j\leq n, bi,j=1b_{i,j}=1 if and only if AiAjA_i\subsetneq A_j. In other words, bi,jb_{i, j} is 11 if AiA_i is a proper subset of AjA_j and 00 otherwise.

Set XX is a proper subset of set YY, if XX is a nonempty subset of YY, and XYX \neq Y.

It's guaranteed that for all test cases in this problem, such nn sets exist. Note that it doesn't mean that such nn sets exist for all possible inputs.

If there are multiple solutions, you can output any of them.

给你一个 nnnn 列的二进制矩阵 bb(矩阵中所有元素均为 0011)。

你需要构造 nn 个集合 A1,A2,,AnA_1, A_2, \ldots, A_n,使得满足以下条件:

  • 每个集合非空,且均由 11nn(含端点)之间的互异整数构成;
  • 所有集合互不相同;
  • 对于所有满足 1i,jn1\leq i, j\leq n 的数对 (i,j)(i,j)bi,j=1b_{i,j}=1 当且仅当 AiAjA_i\subsetneq A_j。换言之,当且仅当 AiA_iAjA_j 的真子集时,bi,j=1b_{i, j} = 1;否则为 00

集合 XX 是集合 YY 的真子集,当且仅当 XXYY 的非空子集,且 XYX \neq Y

本题保证:对所有测试用例,均存在满足要求的 nn 个集合。(注意:这并不意味着对所有可能的输入都存在这样的 nn 个集合。)

若存在多种解法,输出任意一种即可。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1t10001\le t\le 1000) — the number of test cases. The description of test cases follows.

The first line contains a single integer nn (1n1001\le n\le 100).

The following nn lines contain a binary matrix bb, the jj-th character of ii-th line denotes bi,jb_{i,j}.

It is guaranteed that the sum of nn over all test cases does not exceed 10001000.

It's guaranteed that for all test cases in this problem, such nn sets exist.

每个测试包含多个测试用例。第一行包含一个整数 tt1t10001\le t\le 1000),表示测试用例的数量。随后是各测试用例的描述。

第一行包含一个整数 nn1n1001\le n\le 100)。

接下来的 nn 行包含一个二进制矩阵 bb,其中第 ii 行的第 jj 个字符表示 bi,jb_{i,j}

保证所有测试用例的 nn 之和不超过 10001000

保证本题中所有测试用例均存在满足条件的 nn 个集合。

输出格式

For each test case, output nn lines.

For the ii-th line, first output sis_i (1sin)(1 \le s_i \le n) — the size of the set AiA_i. Then, output sis_i distinct integers from 11 to nn — the elements of the set AiA_i.

If there are multiple solutions, you can output any of them.

It's guaranteed that for all test cases in this problem, such nn sets exist.

对于每个测试用例,输出 nn 行。

对于第 ii 行,首先输出 sis_i (1sin)(1 \le s_i \le n) —— 即集合 AiA_i 的大小;然后输出 sis_i 个互不相同的、取值范围在 11nn 之间的整数 —— 即集合 AiA_i 的元素。

若存在多种解法,输出任意一种即可。

本题保证:对所有测试用例,均存在满足条件的 nn 个集合。

输入输出样例

  • 输入#1

    2
    4
    0001
    1001
    0001
    0000
    3
    011
    001
    000

    输出#1

    3 1 2 3
    2 1 3
    2 2 4
    4 1 2 3 4
    1 1
    2 1 2
    3 1 2 3

说明/提示

In the first test case, we have A1=1,2,3,A2=1,3,A3=2,4,A4=1,2,3,4A_1 = {1, 2, 3}, A_2 = {1, 3}, A_3 = {2, 4}, A_4 = {1, 2, 3, 4}. Sets A1,A2,A3A_1, A_2, A_3 are proper subsets of A4A_4, and also set A2A_2 is a proper subset of A1A_1. No other set is a proper subset of any other set.

In the second test case, we have A1=1,A2=1,2,A3=1,2,3A_1 = {1}, A_2 = {1, 2}, A_3 = {1, 2, 3}. A1A_1 is a proper subset of A2A_2 and A3A_3, and A2A_2 is a proper subset of A3A_3.

在第一个测试用例中,我们有 A1=1,2,3,A2=1,3,A3=2,4,A4=1,2,3,4A_1 = {1, 2, 3}, A_2 = {1, 3}, A_3 = {2, 4}, A_4 = {1, 2, 3, 4}。集合 A1,A2,A3A_1, A_2, A_3 均为 A4A_4 的真子集,且集合 A2A_2 也是 A1A_1 的真子集。其余任意两个集合之间均不存在真子集关系。

在第二个测试用例中,我们有 A1=1,A2=1,2,A3=1,2,3A_1 = {1}, A_2 = {1, 2}, A_3 = {1, 2, 3}A1A_1A2A_2A3A_3 的真子集,且 A2A_2A3A_3 的真子集。

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

首页