题目链接:Problem - 1155A - Codeforces
题目中说的是任意子字符串都可以, 那么就可以简化问题了: 找出字符串中字典序递减的子串
那么只需要遍历一遍勋章有没有字典序递减的子串就可以了
ac代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, b) for (ll i = (a); i <= (b); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepr(i, a, b) for (ll i = (b); i > (a); i--)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
ll cnt,n,m,t,ans,ant;
const int N=1e5+10;
ll arr[N];
string str;
inline ll read()
{
char c = getchar();int x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}//是符号
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}//是数字
return x*s;
}
void solve()
{
n=read();
cin>>str;
repr(i,0,n-1)
if(str[i]>str[i+1])
{
puts("YES");
i++;
cout<<i<<' '<<i+1<<endl;
return;
}
puts("NO");
return;
}
int main()
{
t=1;
while(t--)
solve();
return 0;
}