Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. ifstream f("blis.in");
  8. ofstream g("blis.out");
  9.  
  10. const int nmax = 100005;
  11. const int oo = 2000000004;
  12. int k, n, i, j, nr, maxim, poz, lft, rgt, m;
  13. char s[nmax];
  14. vector<pair<int, int> > V[nmax];
  15. int vec[nmax];
  16.  
  17. int cb(int x)
  18. {
  19. int st = 1, dr = m, mij;
  20. while (st <= dr)
  21. {
  22. mij = (st+dr)/2;
  23. if (vec[mij] >= x)
  24. dr = mij-1;
  25. else st = mij+1;
  26. }
  27. return st;
  28. }
  29.  
  30. int main()
  31. {
  32. f >> k >> s+1;
  33. n = strlen(s+1);
  34.  
  35. for (i = 1; i <= n; i++)
  36. vec[i] = oo;
  37. vec[0] = -oo;
  38.  
  39. for (i = 1; i <= n; i++)
  40. {
  41. nr = 0;
  42. for (j = i; j < i+k and j <= n; j++)
  43. {
  44. nr = nr*2+s[j]-'0';
  45. if (maxim < nr)
  46. {
  47. maxim = nr;
  48. }
  49.  
  50. poz = cb(nr);
  51. V[j].push_back(make_pair(poz, nr));
  52. }
  53. int N = V[i].size();
  54. pair<int,int> aux;
  55. for (j = 0;j<N;j++)
  56. {
  57. aux = V[i][j];
  58. if (vec[aux.first] > aux.second)
  59. {
  60. vec[aux.first] = aux.second;
  61. if (aux.first > m)
  62. m++;
  63. }
  64. }
  65. }
  66.  
  67. g << maxim << '\n' << m;
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement