Advertisement
newb_ie

bs3

Aug 29th, 2021
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string s = "abcdabacdabcdef";
  5.  
  6. //~ bool is_unique (string & t) {
  7. //~ set<char> st;
  8. //~ for (int i = 0; i < (int) t.size(); ++i) {
  9. //~ st.insert(t[i]);
  10. //~ }
  11. //~ return (int) t.size() == (int) st.size();
  12. //~ }
  13.  
  14. bool f (int len) {
  15. for (int i = 0; i <= (int) s.size() - len; ++i) {
  16. //~ if (is_unique(s.substr(i,len))) {
  17. //~ return true;
  18. //~ }
  19. set<char> st;
  20. for (int j = i; j < i + len; ++j) {
  21. st.insert(s[j]);
  22. }
  23. if ((int) st.size() == len) {
  24. return true;
  25. }
  26. }
  27. return false;
  28. }
  29.  
  30.  
  31. int main () {
  32. ios::sync_with_stdio(false);
  33. cin.tie(nullptr);
  34. cout.tie(nullptr);
  35. int l = 1,r = 256;
  36. int res = 1;
  37. while (l <= r) {
  38. int mid = (l + r) / 2;
  39. //~ cout << mid << "->";
  40. if (f(mid)) {
  41. res = mid;
  42. l = mid + 1;
  43. } else {
  44. r = mid - 1;
  45. }
  46. }
  47. cout << '\n';
  48. cout << res << '\n';
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement