QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#4632. 紙牌高手

Statistics

桌上有 $n$ 副牌,第 $i$ 副有 $a_i$ 張牌,從上到下第 $j$ 張牌為 $s_{i,j}$。為了簡化問題,我們只考慮大牌和小牌。如果是大牌,則 $s_{i,j}=1$;如果是小牌,則 $s_{i,j}=0$。

有 $m$ 名賭客圍坐在桌旁等著玩牌。你是這場遊戲的發牌員,任務是把所有牌疊成一大疊。你只能控制各副牌之間的順序,不能插入或移除牌,也不能改變一副牌內的牌的順序。

疊好之後,將向賭客發牌。第 $i$ 名賭客會得到從上到下第 $i$、$m+i$、$2m+i$、$\ldots$、$km+i$、$\ldots$ 張牌。其他賭客不知道,第 $b$ 名賭客其實是你的老闆。為了確保勝利,發給老闆的牌必須全是大牌,發給其他賭客的牌必須全是小牌。

找出滿足這項要求的疊牌順序,或報告不可能做到。如果存在合法答案,請給出字典序最小的答案。

顯然,如果答案存在,它是一個長度為 $n$ 的排列。我們稱排列 $P=p_1,p_2,\ldots,p_n$ 的字典序小於排列 $Q=q_1,q_2,\ldots,q_n$,若存在整數 $t$,使得對所有 $1\le i<t$ 都有 $p_i=q_i$,且 $p_t<q_t$。

輸入格式

每個測試檔案只有一組測試資料。

輸入的第一行包含三個整數 $n$、$m$ 和 $b$($1\le n\le2\times10^5$,$2\le m\le2\times10^5$,$1\le b\le m$),分別表示牌的副數、賭客人數及老闆的編號。

接下來 $n$ 行,第 $i$ 行包含字串 $s_{i,1}s_{i,2}\cdots s_{i,a_i}$($s_{i,j}\in\{0,1\}$,$1\le a_i\le10^6$),表示第 $i$ 副牌。

保證:

  • 每副牌至少有一張大牌。

  • 牌的總數能被 $m$ 整除。

  • 牌的總數不超過 $10^6$。

輸出格式

如果存在合法答案,輸出 $n$ 個以空格分隔的整數 $d_1,d_2,\ldots,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.