QOJ.ac

QOJ

时间限制: 1.5 s 内存限制: 64 MB 总分: 100

#17902. 密码

统计

Johnny 对计算机安全非常痴迷:他为每个网站都设置了不同的密码,他会销毁打印件等等。然而,这也成了他的灾难:他意识到自己不小心把写有密码的纸张放进了碎纸机!但幸运的是,这张纸被切碎的方式使得每一条纸片都恰好对应文本的一列。此外,Johnny 确切地知道所有密码都仅由大写英文字母组成,它们两两不同,长度相同,并且最初是按字典序从小到大写下的。Johnny 给这些列编了号并把它们并排放在一起,但他不确定自己摆放的顺序是否正确。请帮助 Johnny——编写一个程序,计算如何重新排列文本的列,使得各行所代表的单词按字典序升序排列。如果存在多种满足条件的排列,选择其中字典序最小的那一个。

输入格式

输入的第一行包含两个自然数 $n, m$ ($1 \le n \cdot m \le 10^6$),用空格隔开。

接下来的 $n$ 行,每行包含一个单词。每个单词由 $m$ 个大写英文字母组成。

输出格式

你应该在一行中输出 $m$ 个自然数——即列的排列,使得排列后各行的单词按字典序排好序。如果存在多个这样的排列,你应该输出其中字典序最小的一个。如果不存在这样的排列,则输出 “NIE”(波兰语中的“否”)。

样例

输入样例 1

2 5
TOMEK
KASIA

输出样例 1

3 1 2 4 5

输入样例 2

3 3
CAB
CBA
BAC

输出样例 2

NIE

说明

在样例 1 中,按照所述方式对列进行排列后,我们得到的单词为:“MTOEK” 和 “SKAIA”,它们是按字典序排好序的。

在样例 2 中,无法通过排列列的顺序使得各行得到的单词按字典序排好序。

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.