fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define fi first
  5. #define se second
  6. #define MOD 1000000007
  7. #define FOR(i,a,b) for (int i = (a);i <= (b);i++)
  8. #define FOD(i,a,b) for (int i = (b);i >= (a);i--)
  9. #define ALL(x) (x).begin(),(x).end()
  10. #define ii pair<int,int>
  11. #define iii pair<int,pair<int,int>>
  12. //const int MOD = 998244353;
  13. const int MAXN = 2e5 + 7;
  14. int a[MAXN];
  15. bool calc(string s,char x){
  16. int mn = 0,id = 1,tot = 0;
  17. FOR(i,1,s.size() - 1){
  18. tot = tot + (s[i] == x ? 1 : -2);
  19. if (tot - mn >= 0 && tot - mn != i - id + 1){
  20. cout << "Yes " << id << ' ' << i << '\n';
  21. return true;
  22. }
  23. if (mn > tot){
  24. mn = tot;
  25. id = i + 1;
  26. }
  27. }
  28. return false;
  29. }
  30. int main(){
  31. ios_base::sync_with_stdio(false);
  32. cin.tie(0); cout.tie(0);
  33. //freopen("cardscore.inp","r",stdin);
  34. //freopen("cardscore.out","w",stdout);
  35. int tt;cin >> tt;
  36. while(tt--){
  37. string s;cin >> s;
  38. s = '+' + s;
  39. if (calc(s,'U'))continue;
  40. if (calc(s,'I'))continue;
  41. cout << "No\n";
  42. }
  43. return 0^0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5320KB
stdin
4
UUUIIIUIIUI
UU
IUUIIUUI
IU
stdout
Yes 1 4
No
Yes 2 4
No