CF1076A.Minimizing the String

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a string ss consisting of nn lowercase Latin letters.

You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation.

String s=s1s2…sns = s_1 s_2 \dots s_n is lexicographically smaller than string t=t1t2…tmt = t_1 t_2 \dots t_m if n<mn \lt m and s1=t1,s2=t2,…,sn=tns_1 = t_1, s_2 = t_2, \dots, s_n = t_n or there exists a number pp such that p≤min(n,m)p \le min(n, m) and s1=t1,s2=t2,…,sp−1=tp−1s_1 = t_1, s_2 = t_2, \dots, s_{p-1} = t_{p-1} and sp<tps_p \lt t_p.

For example, "aaa" is smaller than "aaaa", "abb" is smaller than "abc", "pqr" is smaller than "z".

给你一个由 nn 个小写拉丁字母组成的字符串 ss。

你需要至多删除该字符串中的一个字符(即删除零个或一个字符),使得所得字符串在所有通过此操作可能得到的字符串中字典序最小。

字符串 s=s1s2…sns = s_1 s_2 \dots s_n 的字典序小于字符串 t=t1t2…tmt = t_1 t_2 \dots t_m,当且仅当以下条件之一成立:

  • n<mn \lt m,且 s1=t1,s2=t2,…,sn=tns_1 = t_1, s_2 = t_2, \dots, s_n = t_n;
  • 或存在某个数 pp,满足 p≤min⁡(n,m)p \le \min(n, m),且 s1=t1,s2=t2,…,sp−1=tp−1s_1 = t_1, s_2 = t_2, \dots, s_{p-1} = t_{p-1},同时 sp<tps_p \lt t_p。

例如,“aaa” 小于 “aaaa”,“abb” 小于 “abc”,“pqr” 小于 “z”。

输入格式

The first line of the input contains one integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the length of ss.

The second line of the input contains exactly nn lowercase Latin letters — the string ss.

输入的第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)—— 字符串 ss 的长度。

输入的第二行恰好包含 nn 个小写拉丁字母 —— 字符串 ss。

输出格式

Print one string — the smallest possible lexicographically string that can be obtained by removing at most one character from the string ss.

输出一个字符串——即通过从字符串 ss 中最多删除一个字符所能得到的字典序最小的字符串。

输入输出样例

  • 输入#1

    3
    aaa

    输出#1

    aa
  • 输入#2

    5
    abcda

    输出#2

    abca

说明/提示

In the first example you can remove any character of ss to obtain the string "aa".

In the second example "abca" < "abcd" < "abcda" < "abda" < "acda" < "bcda".

在第一个例子中,你可以删除 ss 的任意一个字符来得到字符串 "aa"。

在第二个例子中,有 "abca" < "abcd" < "abcda" < "abda" < "acda" < "bcda"。

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

首页