CF1575A.Another Sorting Problem

普及-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Andi and Budi were given an assignment to tidy up their bookshelf of nn books. Each book is represented by the book title — a string sis_i numbered from 11 to nn, each with length mm. Andi really wants to sort the book lexicographically ascending, while Budi wants to sort it lexicographically descending.

Settling their fight, they decided to combine their idea and sort it asc-desc-endingly, where the odd-indexed characters will be compared ascendingly, and the even-indexed characters will be compared descendingly.

A string aa occurs before a string bb in asc-desc-ending order if and only if in the first position where aa and bb differ, the following holds:

  • if it is an odd position, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb;
  • if it is an even position, the string aa has a letter that appears later in the alphabet than the corresponding letter in bb.

安迪和布迪接到一项任务,整理他们共 nn 本书的书架。每本书用其书名——一个字符串 sis_i 表示,编号从 11 到 nn,每个字符串长度均为 mm。安迪希望将这些书按字典序升序排列,而布迪则希望按字典序降序排列。

为解决争执,他们决定融合彼此的想法,采用“升-降交替排序”(asc-desc-endingly):即在比较字符串时,奇数位置上的字符按升序比较,偶数位置上的字符按降序比较。

字符串 aa 在升-降交替序中排在字符串 bb 之前,当且仅当在 aa 和 bb 首次出现差异的位置 kk 处,满足以下条件之一:

  • 若 kk 是奇数位置,则 aa 在该位置上的字母在字母表中早于 bb 对应位置上的字母;
  • 若 kk 是偶数位置,则 aa 在该位置上的字母在字母表中晚于 bb 对应位置上的字母。

输入格式

The first line contains two integers nn and mm (1≤n⋅m≤1061 \leq n \cdot m \leq 10^6).

The ii-th of the next nn lines contains a string sis_i consisting of mm uppercase Latin letters — the book title. The strings are pairwise distinct.

第一行包含两个整数 nn 和 mm(1≤n⋅m≤1061 \leq n \cdot m \leq 10^6)。

接下来的 nn 行中,第 ii 行包含一个由 mm 个大写拉丁字母组成的字符串 sis_i —— 书名。这些字符串两两互不相同。

输出格式

Output nn integers — the indices of the strings after they are sorted asc-desc-endingly.

输出 nn 个整数——字符串按升-降序排序后的索引。

输入输出样例

  • 输入#1

    5 2
    AA
    AB
    BB
    BA
    AZ

    输出#1

    5 2 1 3 4

说明/提示

The following illustrates the first example.

以下展示了第一个示例。

输入解题思路,AI测评打分。不知道怎么写?

首页