fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. template<class S, class T> inline S max_L(S a,T b){
  5. return a>=b?a:b;
  6. }
  7. template<class S, class T> inline S chmin(S &a, T b){
  8. if(a>b){
  9. a=b;
  10. }
  11. return a;
  12. }
  13. #define main dummy_main
  14. int main(){
  15. return 0;
  16. }
  17. #undef main
  18. class Solution{
  19. public:
  20. int balancedString(string s){
  21. int i;
  22. int j;
  23. int res;
  24. int cnv[256];
  25. int cnt[4];
  26. int N = s.size();
  27. cnv['Q'] = 0;
  28. cnv['W'] = 1;
  29. cnv['E'] = 2;
  30. cnv['R'] = 3;
  31. for(i=(0);i<(N);i++){
  32. s[i] = cnv[s[i]];
  33. }
  34. for(i=(0);i<(4);i++){
  35. cnt[i] = -(N/4);
  36. }
  37. for(i=(0);i<(N);i++){
  38. cnt[s[i]]++;
  39. }
  40. res = N;
  41. j = 0;
  42. for(i=(0);i<(N);i++){
  43. int Lj4PdHRW;
  44. int KL2GvlyY;
  45. if(4==0){
  46. KL2GvlyY = 0;
  47. }
  48. else{
  49. KL2GvlyY = cnt[0];
  50. for(Lj4PdHRW=(1);Lj4PdHRW<(4);Lj4PdHRW++){
  51. KL2GvlyY = max_L(KL2GvlyY, cnt[Lj4PdHRW]);
  52. }
  53. }
  54. while(j < i || (j < N &&KL2GvlyY> 0)){
  55. int Q5VJL1cS;
  56. int e98WHCEY;
  57. if(4==0){
  58. e98WHCEY = 0;
  59. }
  60. else{
  61. e98WHCEY = cnt[0];
  62. for(Q5VJL1cS=(1);Q5VJL1cS<(4);Q5VJL1cS++){
  63. e98WHCEY = max_L(e98WHCEY, cnt[Q5VJL1cS]);
  64. }
  65. }
  66. if(e98WHCEY<= 0){
  67. break;
  68. }
  69. cnt[s[j++]]--;
  70. }
  71. int cTE1_r3A;
  72. int RZTsC2BF;
  73. if(4==0){
  74. RZTsC2BF = 0;
  75. }
  76. else{
  77. RZTsC2BF = cnt[0];
  78. for(cTE1_r3A=(1);cTE1_r3A<(4);cTE1_r3A++){
  79. RZTsC2BF = max_L(RZTsC2BF, cnt[cTE1_r3A]);
  80. }
  81. }
  82. if(RZTsC2BF> 0){
  83. break;
  84. }
  85. chmin(res, j - i);
  86. cnt[s[i]]++;
  87. }
  88. return res;
  89. }
  90. }
  91. ;
  92. // cLay varsion 20191102-1
  93.  
  94. // --- original code ---
  95. // #define main dummy_main
  96. // {}
  97. // #undef main
  98. //
  99. // class Solution {
  100. // public:
  101. // int balancedString(string s) {
  102. // int i, j, res;
  103. // int cnv[256], cnt[4];
  104. // int N = s.size();
  105. //
  106. // cnv['Q'] = 0;
  107. // cnv['W'] = 1;
  108. // cnv['E'] = 2;
  109. // cnv['R'] = 3;
  110. // rep(i,N) s[i] = cnv[s[i]];
  111. //
  112. // rep(i,4) cnt[i] = -(N/4);
  113. // rep(i,N) cnt[s[i]]++;
  114. // res = N;
  115. // j = 0;
  116. // rep(i,N){
  117. // while(j < i || (j < N && max(cnt(4)) > 0)){
  118. // if(max(cnt(4)) <= 0) break;
  119. // cnt[s[j++]]--;
  120. // }
  121. // if(max(cnt(4)) > 0) break;
  122. // res <?= j - i;
  123. // cnt[s[i]]++;
  124. // }
  125. // return res;
  126. // }
  127. // };
  128.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty