fork download
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #define int long long
  5. #define ll long long
  6. #define ull unsigned long long
  7. #define dl double
  8. #define all(v) v.begin(),v.end()
  9. #define rall(v) v.rbegin(),v.rend()
  10. #define sp " "
  11. #define fi "\n"
  12. #define ld long double
  13. using namespace std;
  14. using namespace __gnu_pbds;
  15. template<typename T>
  16. using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  17. typedef vector<int> vi;
  18. typedef vector<ll> vll;
  19. const int mod = 1e9 + 7;
  20.  
  21. void file() {
  22. #ifndef ONLINE_JUDGE
  23. freopen("input.txt", "r", stdin);
  24. freopen("output.txt", "w", stdout);
  25. // freopen("errors.txt", "w", stderr);
  26. #endif
  27. }
  28.  
  29. void fast() {
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0);
  32. cout.tie(0);
  33. }
  34. int cnt=1;
  35. void solve() {
  36. string s;cin>>s;
  37. int n = s.length();
  38. int l=0,r=0,mini=1e9;
  39. pair<int,int> ans;
  40. vi mp(12);
  41. bool x=0;
  42. while (l<n) {
  43. while (r<n && !x) {
  44. if (s[r]=='0' && r-1>=0 && s[r-1]=='1') {
  45. mp[10]++;
  46. mp[1]--;
  47. r++;
  48. }
  49. else {
  50. mp[s[r]-'0']++;
  51. r++;
  52. }
  53. bool y=0;
  54. for (int i=2;i<=10;i++) {
  55. if (mp[i]<=0)y=1;
  56. }
  57. if ((mp[0]>0&& mp[1]>0 && !y) || (!y && mp[10]>1))
  58. x=1;
  59. }
  60. if (x && r-l<mini) {
  61. mini=r-l;
  62. ans=make_pair(l+1,r);
  63. }
  64. if (s[l]=='1' && l+1<n && s[l+1]=='0') {
  65. mp[0]++;
  66. mp[1]++;
  67. mp[10]--;
  68. }
  69. mp[s[l]-'0']--;
  70. {
  71. bool y=0;
  72. x=0;
  73. for (int i=2;i<=10;i++) {
  74. if (mp[i]<=0)y=1;
  75. }
  76. if ((mp[0]>0 && mp[1]>0 && !y) || (!y && mp[10]>1))
  77. x=1;
  78. }
  79. l++;
  80. }
  81. cout<<"Case "<<cnt++<<": ";
  82. if (mini==1e9)cout<<"NO";
  83. else cout<<"YES "<<ans.first<<" "<<ans.second;
  84. cout<<fi;
  85.  
  86. }
  87. signed main() {
  88. fast();
  89. file();
  90. int off=1;
  91. cin>>off;
  92. while (off--)solve();
  93. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Case 1: NO