QOJ.ac

QOJ

时间限制: 4 s 内存限制: 256 MB 总分: 100

#957. 割り当て問題

统计

会社には $m$ 個の空きポジションがあり、それに対して $n$ 人の候補者($n \ge m$)がいます。当然ながら、私たちは最良の候補者を雇いたいと考えています。同じ候補者を複数のポジションに雇うことはできないため、ちょうど $m$ 人の候補者を雇う必要があります。各ポジションに対して異なる候補者を選ぶ方法を「割り当て(assignment)」と呼びます。2つの割り当ては、あるポジションに対して雇う候補者が異なる場合に異なるとみなされます。

利益を表す行列 $A$ が存在し、$A_{ij} \ge 0$ は $i$ 番目のポジションに $j$ 番目の候補者を雇ったときに得られる利益を表します。私たちは、すべての雇用から得られる利益の総和を最大化したいと考えています。利益の総和を最大化する割り当てを「最適」な割り当てと呼びます。

行列 $A$ が与えられれば、最良の候補者を選ぶことは容易です。しかし残念ながら、人事の世界はそれほど単純ではなく、行列 $A$ を提供してもらうことはできません。すべての候補者と面接した後でも、あるポジションにおいて2人の候補者がどのようなパフォーマンスを示すかを比較することしかできません。より正確には、$m$ 個の長さ $n$ の順列 $P_i$ が与えられています。すべての $1 \le i \le m$ および $1 \le x < y \le n$ に対して、$A_{iP_{ix}} > A_{iP_{iy}}$ が成り立ちます。言い換えれば、各ポジションについて、すべての候補者の順位付けがわかっているということです。

ある候補者が「有望(promising)」であるとは、与えられたすべての順位付けと整合する行列 $A$ が存在し、かつその行列において唯一の最適割り当てが存在し、その割り当てにおいて当該候補者が雇われていることを指します。

より詳細なテストを行うために、すべての有望な候補者を見つけてください。

入力

入力の最初の行には、2つの整数 $n$ と $m$ ($1 \le m \le 11, m \le n \le 1000$) が含まれます。これらは候補者の数とポジションの数を表します。

続く $m$ 行には、各ポジションの順位付けが含まれます。$i$ 番目の行には、$1$ から $n$ までの数字の順列 $P_{i1}, P_{i2}, \dots, P_{in}$ が含まれます。

出力

1行目に有望な候補者の数を出力し、2行目に有望な候補者のインデックスを昇順で出力してください。

入出力例

入力 1

4 2
1 2 4 3
1 3 4 2

出力 1

3
1 2 3

入力 2

4 2
1 4 3 2
2 3 4 1

出力 2

2
1 2

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#317EditorialOpen题解jiangly2026-01-09 10:10:43View

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.