A14240 | Maximize the Remaining String
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a string $s$ , consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation:
- you choose the index $i$ ( $1 \le i \le |s|$ ) such that the character at position $i$ occurs at least two times in the string $s$ , and delete the character at position $i$ , that is, replace $s$ with $s_1 s_2 \ldots s_{i-1} s_{i+1} s_{i+2} \ldots s_n$ .
For example, if $s=$ "codeforces", then you can apply the following sequence of operations:
- $i=6 \Rightarrow s=$ "codefrces";
- $i=1 \Rightarrow s=$ "odefrces";
- $i=7 \Rightarrow s=$ "odefrcs";
Given a given string $s$ , find the lexicographically maximum string that can be obtained after applying a certain sequence of operations after which all characters in the string become unique.
A string $a$ of length $n$ is lexicographically less than a string $b$ of length $m$ , if:
- there is an index $i$ ( $1 \le i \le \min(n, m)$ ) such that the first $i-1$ characters of the strings $a$ and $b$ are the same, and the $i$ -th character of the string $a$ is less than $i$ -th character of string $b$ ;
- or the first $\min(n, m)$ characters in the strings $a$ and $b$ are the same and $n < m$ .
For example, the string $a=$ "aezakmi" is lexicographically less than the string $b=$ "aezus".
- you choose the index $i$ ( $1 \le i \le |s|$ ) such that the character at position $i$ occurs at least two times in the string $s$ , and delete the character at position $i$ , that is, replace $s$ with $s_1 s_2 \ldots s_{i-1} s_{i+1} s_{i+2} \ldots s_n$ .
For example, if $s=$ "codeforces", then you can apply the following sequence of operations:
- $i=6 \Rightarrow s=$ "codefrces";
- $i=1 \Rightarrow s=$ "odefrces";
- $i=7 \Rightarrow s=$ "odefrcs";
Given a given string $s$ , find the lexicographically maximum string that can be obtained after applying a certain sequence of operations after which all characters in the string become unique.
A string $a$ of length $n$ is lexicographically less than a string $b$ of length $m$ , if:
- there is an index $i$ ( $1 \le i \le \min(n, m)$ ) such that the first $i-1$ characters of the strings $a$ and $b$ are the same, and the $i$ -th character of the string $a$ is less than $i$ -th character of string $b$ ;
- or the first $\min(n, m)$ characters in the strings $a$ and $b$ are the same and $n < m$ .
For example, the string $a=$ "aezakmi" is lexicographically less than the string $b=$ "aezus".
输入格式
The first line contains one integer $t$ ( $1 \le t \le 10^4$ ). Then $t$ test cases follow.
Each test case is characterized by a string $s$ , consisting of lowercase Latin letters ( $1 \le |s| \le 2 \cdot 10^5$ ).
It is guaranteed that the sum of the lengths of the strings in all test cases does not exceed $2 \cdot 10^5$ .
Each test case is characterized by a string $s$ , consisting of lowercase Latin letters ( $1 \le |s| \le 2 \cdot 10^5$ ).
It is guaranteed that the sum of the lengths of the strings in all test cases does not exceed $2 \cdot 10^5$ .
输出格式
For each test case, output the lexicographically maximum string that can be obtained after applying a certain sequence of operations after which all characters in the string become unique.
输入输出样例
输入 #1
6 codeforces aezakmi abacaba convexhull swflldjgpaxs myneeocktxpqjpz
输出 #1
odfrces ezakmi cba convexhul wfldjgpaxs myneocktxqjpz
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted