CF1250E.The Coronation

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

The coronation of King Berl XXII is soon! The whole royal family, including nn daughters of Berl XXII, will be present.

The King has ordered his jeweler to assemble nn beautiful necklaces, so each of the princesses could wear exactly one necklace during the ceremony — and now these necklaces are finished. Each necklace consists of mm gems attached to a gold chain. There are two types of gems used in the necklaces — emeralds and sapphires. So, each necklace can be represented by a sequence of mm gems (listed from left to right), and each gem is either an emerald or a sapphire. Formally, the ii-th necklace can be represented by a binary string sis_i of length mm; if the jj-th character of sis_i is 0, then the jj-th gem in the ii-th necklace is an emerald; otherwise, this gem is a sapphire.

Now, looking at the necklaces, the King is afraid that some of his daughters may envy the other daughters' necklaces. He wants all necklaces to look similar. Two necklaces are considered similar if there are at least kk positions where these necklaces contain the same type of gems.

For example, if there is a necklace represented by a sequence 01010111 and a necklace represented by a sequence 01100000, then there are 33 positions where these necklaces contain the same type of gems (both first gems are emeralds, both second gems are sapphires, and both fifth gems are emeralds). So if k=3k = 3, these necklaces are similar, and if k=4k = 4, they are not similar.

The King thinks that if two of his daughters notice that their necklaces are not similar, then they may have a conflict — and, obviously, he doesn't want any conflicts during the coronation! So Berl XXII wants to tell some of his daughters to wear their necklaces backward. If a necklace is worn backward, then the sequence of gems in this necklace is reversed. For example, if a necklace is represented by a sequence 01100, then, if worn backward, it would be represented by a sequence 00110. The King wants to find the minimum number of necklaces to be worn backward during the coronation so that there are no conflicts.

Berl XXII is too busy with preparation for the coronation, so he ordered you to resolve this issue for him. Help him — and he will give you a truly royal reward!

国王贝尔二十二世的加冕典礼即将到来!整个王室家族,包括贝尔二十二世的 nn 位公主,都将出席典礼。

国王已命令御用珠宝匠制作 nn 条精美的项链,以便每位公主在典礼上恰好佩戴一条——如今这些项链均已完工。每条项链由串在金链上的 mm 颗宝石组成。项链中仅使用两种宝石:祖母绿与蓝宝石。因此,每条项链可表示为一个长度为 mm 的宝石序列(从左至右列出),且每颗宝石要么是祖母绿,要么是蓝宝石。形式化地,第 ii 条项链可用一个长度为 mm 的二进制字符串 sis_i 表示;若 sis_i 的第 jj 个字符为 0,则第 ii 条项链的第 jj 颗宝石为祖母绿;否则该宝石为蓝宝石。

此时,国王审视着这些项链,担心某些公主会嫉妒其他公主的项链。他希望所有项链看起来都足够相似。若两条项链在至少 kk 个位置上拥有相同类型的宝石,则称这两条项链是相似的。

例如,若一条项链表示为序列 01010111,另一条项链表示为序列 01100000,则这两条项链在 33 个位置上拥有相同类型的宝石(第一颗宝石均为祖母绿,第二颗宝石均为蓝宝石,第五颗宝石均为祖母绿)。因此,当 k=3k = 3 时,这两条项链是相似的;而当 k=4k = 4 时,它们不相似。

国王认为,若两位公主发现彼此的项链不相似,则可能引发冲突——显然,他在加冕典礼期间绝不希望出现任何冲突!因此,贝尔二十二世希望让部分公主将项链反向佩戴。若一条项链被反向佩戴,则其宝石序列将被反转。例如,若一条项链表示为序列 01100,则反向佩戴后其表示变为 00110。国王希望找出在典礼上需反向佩戴的项链的最小数目,使得任意两条项链均相似(即不存在冲突)。

贝尔二十二世正忙于加冕典礼的筹备工作,因此他委派你解决这一问题。请助他一臂之力——作为回报,他将赐予你一份真正尊贵的赏赐!

输入格式

The first line contains one integer tt (1≤t≤501 \le t \le 50) — the number of test cases. Then the test cases follow.

Each test case begins with a line containing three integers nn, mm and kk (2≤n≤502 \le n \le 50, 1≤k≤m≤501 \le k \le m \le 50) — the number of necklaces, the number of gems in each necklace, and the minimum number of positions where two necklaces have to have the same type of gems in order to look similar, respectively.

Then nn lines follow, the ii-th of them contains a binary string sis_i of length mm representing the ii-th necklace.

第一行包含一个整数 tt(1≤t≤501 \le t \le 50),表示测试用例的数量。随后是各测试用例。

每个测试用例首先是一行,包含三个整数 nn、mm 和 kk(2≤n≤502 \le n \le 50,1≤k≤m≤501 \le k \le m \le 50),分别表示项链的数量、每条项链上宝石的数量,以及两条项链被视为“相似”所需在至少多少个位置上具有相同类型宝石的最小位置数。

接下来是 nn 行,其中第 ii 行包含一个长度为 mm 的二进制字符串 sis_i,表示第 ii 条项链。

输出格式

For each test case, print the answer as follows.

If it is impossible to avoid the conflict, print -1 on a single line. In this case you should not output anything else for that test case.

Otherwise, the first line of the test case answer should contain the single integer dd — the minimum number of necklaces that are to be worn backward. The second line of the test case answer should contain the numbers of these necklaces (integers from 11 to nn) in any order. If d=0d = 0 then leave the second line of the test case answer empty. If there are multiple answers, you may print any of them.

对于每个测试用例,请按如下方式输出答案:

如果无法避免冲突,则在单独一行中输出 -1。此时,该测试用例不应再输出其他任何内容。

否则,该测试用例答案的第一行应包含一个整数 dd —— 即需反向佩戴的项链的最小数量;第二行应包含这些项链的编号(为从 11 到 nn 的整数),顺序任意。若 d=0d = 0,则该测试用例答案的第二行应为空行。若存在多个可行答案,输出其中任意一个即可。

输入输出样例

  • 输入#1

    5
    5 7 2
    1010100
    0010101
    1111010
    1000010
    0000101
    6 9 3
    011111110
    100111000
    111100000
    000111111
    110100111
    111110111
    3 4 2
    0001
    1000
    0000
    3 4 4
    0001
    1000
    0000
    2 4 3
    0001
    1000

    输出#1

    2
    1 3 
    1
    3 
    0
    
    -1
    1
    1

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

首页