fork(2) download
  1. mid=(low+high)/2
  2. low=k,high=string.size()
  3. ans=-1
  4. while(low<=high):
  5. mid=(low+high)/2
  6. ll flag=0 // to check if there is a string with length mid>=k that can be made palindrome
  7. for(i=0;i+mi-1<=string.size();i++)
  8. {
  9. ll ctr=0;
  10. for(j=0;j<26;j++)
  11. {
  12. ctr+=(dp[i+mi-1][j]-dp[i-1][j])%2; // counting chars with odd frequency
  13. }
  14. if(k%2==0)
  15. {
  16. if(ctr==0) // all chars appear even no. of times
  17. {
  18. flag=1; // found a string
  19. break;
  20. }
  21. else
  22. {
  23. ll cur_len=mid-ctr; // remove single appearance of all chars with odd frequency
  24. if(cur_len>=k)
  25. {
  26. flag=1;
  27. break;
  28. }
  29. }
  30. }
  31. else
  32. {
  33. if(ctr!=0) // odd palindrome should have atleast one char with odd frequency
  34. {
  35. ll cur_len=mid-ctr+1; // adding 1 to include one odd char
  36. if(cur_len>=k)
  37. {
  38. flag=1;
  39. break;
  40. }
  41. }
  42. else
  43. {
  44. if(mid-1>=k) // just remove one occurrence of a character to make it's frequency odd
  45. {
  46. flag=1;
  47. break;
  48. }
  49. }
  50. }
  51. }
  52. if(flag)
  53. {
  54. ans=mi;
  55. lo=mi+1;
  56. }
  57. else
  58. {
  59. hi=mi-1;
  60. }
  61. }
  62. cout<<ans;
  63.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: C++ requires a type specifier for all declarations
mid=(low+high)/2
^
prog.cpp:1:6: error: use of undeclared identifier 'low'
mid=(low+high)/2
     ^
prog.cpp:1:10: error: use of undeclared identifier 'high'
mid=(low+high)/2
         ^
prog.cpp:2:11: error: expected ';' after top level declarator
low=k,high=string.size()
          ^
          ;
prog.cpp:61:1: error: extraneous closing brace ('}')
}
^
prog.cpp:62:1: error: unknown type name 'cout'
cout<<ans;
^
prog.cpp:62:5: error: expected unqualified-id
cout<<ans;
    ^
7 errors generated.
stdout
Standard output is empty