CF1155A.Reverse a Substring

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a string ss consisting of nn 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 33 and ends in position 66 ), but "aa" or "d" aren't substrings of this string. So the substring of the string ss from position ll to position rr is s[l;r]=slsl+1srs[l; r] = s_l s_{l + 1} \dots s_r .

You have to choose exactly one of the substrings of the given string and reverse it (i. e. make s[l;r]=srsr1sls[l; r] = s_r s_{r - 1} \dots s_l ) 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 xx is lexicographically less than string yy , if either xx is a prefix of yy (and xyx \ne y ), or there exists such ii ( 1imin(x,y)1 \le i \le min(|x|, |y|) ), that xi<yix_i < y_i , and for any jj ( 1j<i1 \le j < i ) xj=yjx_j = y_j . Here a|a| denotes the length of the string aa . The lexicographic comparison of strings is implemented by operator < in modern programming languages​​.

输入格式

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

The second line of the input contains the string ss of length nn consisting only of lowercase Latin letters.

输出格式

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 ll and rr ( 1l<rn1 \le l < r \le n ) denoting the substring you have to reverse. If there are multiple answers, you can print any.

输入输出样例

  • 输入#1

    7
    abacaba
    

    输出#1

    YES
    2 5
    
  • 输入#2

    6
    aabcfg
    

    输出#2

    NO
    

说明/提示

In the first testcase the resulting string is "aacabba".

首页