QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 1024 MB 총점: 100

#4632. 玩牌高手

통계

桌上有 $n$ 副牌,第 $i$ 副牌包含 $a_i$ 张牌,从上到下第 $j$ 张牌记为 $s_{i,j}$。为了简化问题,我们只考虑牌的高低。如果牌是高牌,则 $s_{i,j} = 1$;如果是低牌,则 $s_{i,j} = 0$。

有 $m$ 名赌徒围坐在桌旁等待玩牌。你是游戏的荷官,你的任务是将所有牌堆叠成一大摞。你只能控制牌堆之间的顺序,既不能插入或移除牌,也不能改变单副牌内部的顺序。

牌堆叠好后,牌将发给赌徒。第 $i$ 名赌徒将从上到下依次获得第 $i$ 张、第 $(m+i)$ 张、第 $(2m+i)$ 张、...、第 $(km+i)$ 张牌。其他赌徒不知道的是,第 $b$ 名赌徒实际上是你的老板。为了确保胜利,发给老板的所有牌必须是高牌,而发给其他所有赌徒的牌必须是低牌。

请找到一种堆叠牌堆的顺序以满足此要求,或者报告这是不可能的。如果存在有效的答案,请输出字典序最小的那个。

如果答案存在,它显然是 $n$ 的一个排列。我们称排列 $P = p_1, p_2, \dots, p_n$ 比排列 $Q = q_1, q_2, \dots, q_n$ 字典序更小,如果存在一个整数 $t$,使得对于所有 $1 \le i < t$ 都有 $p_i = q_i$,且 $p_t < q_t$。

输入格式

每个测试文件中只有一个测试用例。

第一行包含三个整数 $n, m$ 和 $b$ ($1 \le n \le 2 \times 10^5, 2 \le m \le 2 \times 10^5, 1 \le b \le m$),分别表示牌堆的数量、赌徒的数量和老板的编号。

接下来的 $n$ 行中,第 $i$ 行包含一个字符串 $s_{i,1}s_{i,2} \dots s_{i,a_i}$ ($s_{i,j} \in \{0, 1\}, 1 \le a_i \le 10^6$),表示第 $i$ 副牌。

保证: 每副牌中至少有一张高牌。 牌的总数能被 $m$ 整除。 * 牌的总数不超过 $10^6$。

输出格式

如果存在有效的答案,输出 $n$ 个整数 $d_1, d_2, \dots, d_n$,用空格分隔,表示字典序最小的答案,其中 $d_i$ 是从上到下第 $i$ 个牌堆的编号。

如果不存在有效的答案,直接输出 “-1”(不含引号)。

样例

输入 1

5 4 3
0100010
00100
001000100
0010
0100010

输出 1

2 1 3 5 4

输入 2

4 2 1
010
10101
010
10101

输出 2

2 1 4 3

输入 3

1 5 3
001000010000100

输出 3

1

输入 4

2 5 3
01000
00010

输出 4

-1

输入 5

1 5 3
11111

输出 5

-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.