Advertisement
a53

Blis

a53
Mar 10th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include<cstdio>
  2. #include<cstring>
  3. using namespace std;
  4. struct nod{int val,lg; nod *urm;};
  5. nod *P[100010],*paux;
  6. int k,n,i,v,j,K,ST,DR,MI,LMAX,sol,BST[100010],oo=2000000000;
  7. char B[100010];
  8. int main()
  9. {
  10. freopen("blis.in","r",stdin);
  11. freopen("blis.out","w",stdout);
  12. scanf("%d",&k);
  13. scanf("%s",B+1);
  14. n=strlen(B+1);
  15. for(i=1;i<=n+1;i++)BST[i]=oo;BST[0]=-oo;LMAX=0;
  16. for(i=1;i<=n;i++)
  17. {
  18. v=0;K=i+k-1<n?i+k-1:n;
  19. for(j=i;j<=K;j++)
  20. {
  21. v<<=1;v|=B[j]-'0';sol=v>sol?v:sol;
  22. for(ST=0,DR=LMAX+1;DR-ST-1;)
  23. {
  24. MI=(ST+DR)>>1;
  25. if(BST[MI]<v)ST=MI;
  26. else DR=MI;
  27. }
  28. if(v<BST[DR])
  29. {
  30. paux=new nod;paux->val=v;paux->lg=DR;paux->urm=P[j];P[j]=paux;
  31. }
  32. }
  33. for(;P[i];)
  34. {
  35. paux=P[i];P[i]=P[i]->urm;
  36. if(BST[paux->lg]>paux->val)BST[paux->lg]=paux->val;
  37. delete paux;
  38. }
  39. while(BST[LMAX+1]<oo)LMAX++;
  40. }
  41. printf("%d\n%d",sol,LMAX);
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement