CF1765A.Access Levels

普及/提高-

通过率:0%

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 k1k \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?

输入格式

The first line contains two integers nn and mm ( 1n,m5001 \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.

输出格式

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.

输入输出样例

  • 输入#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.

首页