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$ 嘅排列。如果有一個整數 $t$,令所有 $1\le i<t$ 都有 $p_i=q_i$,而且 $p_t<q_t$,我哋就話排列 $P=p_1,p_2,\ldots,p_n$ 嘅字典序細過排列 $Q=q_1,q_2,\ldots,q_n$。

輸入格式

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

輸入第一行有三個整數 $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.