cswork / OA打开练习工作台

AmazonOA #364

Erase Pairs

估计中等可在线判题

考点(AI 标注)单调栈与堆贪心调度字符串

In each step you may delete any two equal characters, which need not be adjacent; the remaining characters keep their original order. First minimize the remaining length, then make the remaining string lexicographically smallest by Unicode code point.

输入格式

The input is a JSON string. On this site 0≤length in code points≤200000, and all Unicode scalar characters are allowed, including whitespace, NUL, non-BMP characters and U+0085/U+2028/U+2029.

输出格式

Output a canonical ASCII JSON string followed by a newline: double quotes and backslashes are escaped with a backslash; control characters use JSON short escapes (backspace, tab, newline, form feed, carriage return) or a lowercase four-digit \u; non-ASCII characters and DEL use a lowercase four-digit \u, and non-BMP characters use a pair of UTF-16 surrogate escapes; all other printable ASCII is output directly. This is equivalent to Python json.dumps(result, ensure_ascii=True). An empty string is output as "". The exact comparison mode is used, so spaces inside the string cannot be ignored.

样例 1

输入:

"CBCAAXA"

输出:

"BAX"

样例 2

输入:

"ZYXZYZY"

输出:

"XYZ"

样例 3

输入:

"ABCBACDDAA"

输出:

""

样例说明

The outputs are "BAX", "XYZ" and "". The original third example shows a single space, which conflicts with its explicit explanation of an empty string; this site corrects it to an empty JSON string.