A14501 | Another Sorting Problem
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Andi and Budi were given an assignment to tidy up their bookshelf of $n$ books. Each book is represented by the book title — a string $s_i$ numbered from $1$ to $n$ , each with length $m$ . 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 $a$ occurs before a string $b$ in asc-desc-ending order if and only if in the first position where $a$ and $b$ differ, the following holds:
- if it is an odd position, the string $a$ has a letter that appears earlier in the alphabet than the corresponding letter in $b$ ;
- if it is an even position, the string $a$ has a letter that appears later in the alphabet than the corresponding letter in $b$ .
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 $a$ occurs before a string $b$ in asc-desc-ending order if and only if in the first position where $a$ and $b$ differ, the following holds:
- if it is an odd position, the string $a$ has a letter that appears earlier in the alphabet than the corresponding letter in $b$ ;
- if it is an even position, the string $a$ has a letter that appears later in the alphabet than the corresponding letter in $b$ .
输入格式
The first line contains two integers $n$ and $m$ ( $1 \leq n \cdot m \leq 10^6$ ).
The $i$ -th of the next $n$ lines contains a string $s_i$ consisting of $m$ uppercase Latin letters — the book title. The strings are pairwise distinct.
The $i$ -th of the next $n$ lines contains a string $s_i$ consisting of $m$ uppercase Latin letters — the book title. The strings are pairwise distinct.
输出格式
Output $n$ integers — the indices of the strings after they are sorted asc-desc-endingly.
输入输出样例
输入 #1
5 2 AA AB BB BA AZ
输出 #1
5 2 1 3 4
The following illustrates the first example.


C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted