CF1155A.Reverse a Substring
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s consisting of n lowercase Latin letters.
Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from position l to position r is s[l;r]=slsl+1…sr.
You have to choose exactly one of the substrings of the given string and reverse it (i. e. make s[l;r]=srsr−1…sl) to obtain a string that is less lexicographically. Note that it is not necessary to obtain the minimum possible string.
If it is impossible to reverse some substring of the given string to obtain a string that is less, print "NO". Otherwise print "YES" and any suitable substring.
String x is lexicographically less than string y, if either x is a prefix of y (and x=y), or there exists such i (1≤i≤min(∣x∣,∣y∣)), that xi<yi, and for any j (1≤j<i) xj=yj. Here ∣a∣ denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages.
给你一个由 n 个小写拉丁字母组成的字符串 s。
我们定义子串为字符串的一个连续子段。例如,“acab” 是 “abacaba” 的一个子串(它起始于位置 3,终止于位置 6),但 “aa” 或 “d” 并不是该字符串的子串。因此,字符串 s 中从位置 l 到位置 r 的子串记为 s[l;r]=slsl+1…sr。
你需要恰好选择给定字符串的一个子串,并将其反转(即令 s[l;r]=srsr−1…sl),使得所得字符串在字典序上严格小于原字符串。注意:不一定要得到字典序最小的可能字符串。
如果不可能通过反转某个子串来得到字典序更小的字符串,则输出 "NO";否则输出 "YES",并给出任意一个满足条件的子串(即其起始与结束位置)。
字符串 x 在字典序上小于字符串 y,当且仅当以下任一条件成立:
- x 是 y 的真前缀(即 x=y,且 y 以 x 开头);
- 或存在某个下标 i(1≤i≤min(∣x∣,∣y∣)),使得 xi<yi,且对所有 j(1≤j<i)均有 xj=yj。
其中 ∣a∣ 表示字符串 a 的长度。现代编程语言中,字符串的字典序比较即由运算符<实现。
输入格式
The first line of the input contains one integer n (2≤n≤3⋅105) — the length of s.
The second line of the input contains the string s of length n consisting only of lowercase Latin letters.
输入的第一行包含一个整数 n(2≤n≤3⋅105)—— 字符串 s 的长度。
输入的第二行包含一个长度为 n 的字符串 s,仅由小写拉丁字母组成。
输出格式
If it is impossible to reverse some substring of the given string to obtain a string which is lexicographically less, print "NO". Otherwise print "YES" and two indices l and r (1≤l<r≤n) denoting the substring you have to reverse. If there are multiple answers, you can print any.
如果无法通过反转给定字符串的某个子串来得到字典序更小的字符串,则输出 "NO"。否则,输出 "YES" 以及两个下标 l 和 r(1≤l<r≤n),表示需要反转的子串。若存在多个答案,输出任意一个即可。
输入输出样例
输入#1
7 abacaba
输出#1
YES 2 5
输入#2
6 aabcfg
输出#2
NO
说明/提示
In the first testcase the resulting string is "aacabba".
在第一个测试用例中,得到的字符串为 "aacabba"。
输入解题思路,AI测评打分。不知道怎么写?