ProgMe

Untitled

Dec 13th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. #pragma GCC optimization("O3")
  5.  
  6. using namespace std;
  7.  
  8. int32_t main()
  9. {
  10. ios::sync_with_stdio(false);
  11. cin.tie(nullptr); cout.tie(nullptr);
  12. unsigned int n;
  13. cin >> n;
  14. unsigned int now = 1;
  15. while(now<<1U <= n)
  16. now <<= 1U;
  17. string s = "0";
  18. while(now >= 1U){
  19. if(n >= now)
  20. n -= now, s += '1';
  21. else
  22. s += '0';
  23. if(now == 1)
  24. break;
  25. now >>= 1U;
  26. }
  27. unsigned int ans = 0;
  28. now = 0;
  29. bool fnd = false;
  30. for(char i : s){
  31. if(now == 0){
  32. fnd = 1 - (i - '0');
  33. now++;
  34. continue;
  35. }
  36. if(fnd == i - '0')
  37. fnd = 1 - fnd, now++;
  38. else {
  39. ans = max(ans, now);
  40. now = 1;
  41. fnd = 1 - (i - '0');
  42. }
  43. }
  44. ans = max(ans, now);
  45. cout << ans;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment