Advertisement
BaoJIaoPisu

Untitled

Aug 2nd, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pb push_back
  5. #define pf push_front
  6. #define popb pop_back
  7. #define popf pop_front
  8. #define ins insert
  9. #define pq priority_queue
  10. #define minele min_element
  11. #define maxele max_element
  12. #define lb lower_bound //first pos >= val
  13. #define ub upper_bound // first pos > val
  14. #define cnt_bit __builtin_popcount
  15. #define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  16. //#pragma GCC optimize("Ofast")
  17. //#pragma GCC target("avx,avx2,fma")
  18. using namespace std;
  19.  
  20. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  21.  
  22. typedef long long ll;
  23. typedef pair<ll, ll> pll;
  24. typedef pair<int, int> pii;
  25.  
  26.  
  27. int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
  28. int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  29. int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};
  30.  
  31. const ll oo = 1e18;
  32. const ll maxN = 1e6;
  33.  
  34. /* Author : Le Ngoc Bao Anh, 10A5, LQD High School for Gifted Student */
  35.  
  36. void maximize(int &a, int b) {
  37.     a = max(a, b);
  38. }
  39.  
  40. void minimize(int &a, int b) {
  41.     a = min(a, b);
  42. }
  43.  
  44. int pref[maxN][30];
  45.  
  46. void solve() {
  47.     string s; cin >> s;
  48.     int n = s.size(); s = "#" + s;
  49.     int k; cin >> k;
  50.  
  51.     int ans = min(k, n);
  52.     for(int i = 1; i <= n; i++) {
  53.         int x = (s[i] - 'a' + 1);
  54.         for(int j = 1; j <= 26; j++) pref[i][j] = pref[i - 1][j];
  55.         pref[i][x]++;
  56.     }
  57.  
  58.     for(int i = 1; i <= n; i++) {
  59.         int L = i, R = n;
  60.         while(L <= R) {
  61.             int mid = (L + R) >> 1;
  62.             bool ok = false;
  63.             for(int j = 1; j <= 26; j++) {
  64.                 int x = (pref[mid][j] - pref[i - 1][j]);
  65.                 if(x + k >= mid - i + 1) {
  66.                     ok = true;
  67.                 }
  68.             }
  69.  
  70.             if(ok) {
  71.                 ans = max(ans, mid - i + 1);
  72.                 L = mid + 1;
  73.             } else R = mid - 1;
  74.         }
  75.     }
  76.  
  77.     cout << ans;
  78. }
  79.  
  80. int main()
  81. {
  82.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  83.     #ifndef ONLINE_JUDGE
  84.     freopen("input.txt", "r", stdin);
  85.     freopen("output.txt", "w", stdout);
  86.     #else
  87.     //online
  88.     #endif
  89.  
  90.     int tc = 1, ddd = 0;
  91.     // cin >> tc;
  92.     while(tc--) {
  93.         //ddd++;
  94.         //cout << "Case #" << ddd << ": ";
  95.         solve();
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement