CF1765A.Access Levels

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

BerSoft is the biggest IT corporation in Berland, and Monocarp is the head of its security department. This time, he faced the most difficult task ever.

Basically, there are nn developers working at BerSoft, numbered from 11 to nn. There are mm documents shared on the internal network, numbered from 11 to mm. There is a table of access requirements aa such that ai,ja_{i,j} (the jj-th element of the ii-th row) is 11 if the ii-th developer should have access to the jj-th document, and 00 if they should have no access to it.

In order to restrict the access, Monocarp is going to perform the following actions:

  • choose the number of access groups k≥1k \ge 1;
  • assign each document an access group (an integer from 11 to kk) and the required access level (an integer from 11 to 10910^9);
  • assign each developer kk integer values (from 11 to 10910^9) — their access levels for each of the access groups.

The developer ii has access to the document jj if their access level for the access group of the document is greater than or equal to the required access level of the document.

What's the smallest number of access groups Monocarp can choose so that it's possible to assign access groups and access levels in order to satisfy the table of access requirements?

BerSoft 是 Berland 国内规模最大的 IT 公司,而 Monocarp 是其安全部门的负责人。这一次,他面临了有史以来最困难的任务。

简而言之,BerSoft 共有 nn 名开发者,编号为 11 至 nn;公司内部网络上共享着 mm 份文档,编号为 11 至 mm。存在一张访问权限需求表 aa,其中 ai,ja_{i,j}(即第 ii 行的第 jj 个元素)为 11 表示第 ii 名开发者应当拥有对第 jj 份文档的访问权限,为 00 则表示不应拥有该文档的访问权限。

为了限制访问权限,Monocarp 将执行以下操作:

  • 选定访问组的数量 k≥1k \ge 1;
  • 为每份文档分配一个访问组(取值为 11 至 kk 的整数)以及一个所需的访问等级(取值为 11 至 10910^9 的整数);
  • 为每位开发者分配 kk 个整数值(取值均为 11 至 10910^9),分别表示其在各个访问组中的访问等级。

当且仅当开发者 ii 在文档 jj 所属访问组中的访问等级 大于等于 文档 jj 所需的访问等级时,开发者 ii 才能访问文档 jj。

问:Monocarp 能选择的最小访问组数量 kk 是多少,使得存在一种访问组与访问等级的分配方案,能够完全满足上述访问权限需求表?

输入格式

The first line contains two integers nn and mm (1≤n,m≤5001 \le n, m \le 500) — the number of developers and the number of documents.

Each of the next nn lines contains a binary string of length mm — the table of access requirements. The jj-th element of the ii-th row is 11 if the ii-th developer should have access to the jj-th document, and 00 if they should have no access to it.

第一行包含两个整数 nn 和 mm(1≤n,m≤5001 \le n, m \le 500)—— 分别表示开发人员数量和文档数量。

接下来的 nn 行,每行包含一个长度为 mm 的二进制字符串,表示访问权限要求表。第 ii 行的第 jj 个元素为 11 表示第 ii 位开发人员应有权访问第 jj 个文档;为 00 则表示其不应拥有对该文档的访问权限。

输出格式

The first line should contain a single integer kk — the smallest number of access groups Monocarp can choose so that it's possible to assign access groups and access levels in order to satisfy the table of access requirements.

The second line should contain mm integers from 11 to kk — the access groups of the documents.

The third line should contain mm integers from 11 to 10910^9 — the required access levels of the documents.

The ii-th of the next nn lines should contain kk integers from 11 to 10910^9 — the access level of the ii-th developer on each of the access groups.

If there are multiple solutions, print any of them.

第一行应包含一个整数 kk —— Monocarp 能选择的最小访问组数量,使得存在一种方式为文档分配访问组和访问级别,从而满足访问需求表。

第二行应包含 mm 个介于 11 到 kk 之间的整数 —— 各文档所属的访问组。

第三行应包含 mm 个介于 11 到 10910^9 之间的整数 —— 各文档所需的访问级别。

接下来的 nn 行中,第 ii 行应包含 kk 个介于 11 到 10910^9 之间的整数 —— 第 ii 位开发者在各访问组上的访问级别。

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

输入输出样例

  • 输入#1

    3 2
    01
    11
    10

    输出#1

    2
    1 2 
    2 2 
    1 2 
    2 2 
    2 1
  • 输入#2

    2 3
    101
    100

    输出#2

    1
    1 1 1
    1 10 5
    8
    3

说明/提示

In the first example, we assign the documents to different access groups. Both documents have level 22 in their access group. This way, we can assign the developers, who need the access, level 22, and the developers, who have to have no access, level 11.

If they had the same access group, it would be impossible to assign access levels to developers 11 and 33. Developer 11 should've had a lower level than developer 33 in this group to not be able to access document 11. At the same time, developer 33 should've had a lower level than developer 11 in this group to not be able to access document 22. Since they can't both have lower level than each other, it's impossible to have only one access group.

In the second example, it's possible to assign all documents to the same access group.

在第一个例子中,我们将文档分配给不同的访问组。两个文档在其所属的访问组中均具有等级 22。这样,我们可以为需要访问权限的开发人员分配等级 22,而为必须禁止访问的开发人员分配等级 11。

如果它们属于同一访问组,则无法为开发人员 11 和开发人员 33 分配合适的访问等级:

  • 开发人员 11 在该组中的等级需低于开发人员 33,才能无法访问文档 11;
  • 同时,开发人员 33 在该组中的等级又需低于开发人员 11,才能无法访问文档 22。
    由于二者不可能互为更低等级,因此仅使用一个访问组是不可能实现的。

在第二个例子中,可以将所有文档分配到同一个访问组。

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

首页