Advertisement
a53

PalPal

a53
Apr 28th, 2020
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define N 100001
  3. using namespace std;
  4. char s[N];
  5. int k,l,i,nr,L,sol[N],aux[N];
  6. bool F[N],F1[N];
  7.  
  8. void solve(int start)
  9. {
  10. int sz=0;
  11. nr=0;
  12. for(i=0;i+start+1<L;++i)
  13. if(s[i]==s[i+start+1])
  14. F[i]=0,++nr,aux[sz]=i,++sz;
  15. sol[start+2]=nr;
  16. for(l=start+2;l+2<=k;l+=2)
  17. {
  18. nr=0;
  19. int sz2=sz;
  20. sz=0;
  21. for(int poz=0;poz<sz2;++poz)
  22. {
  23. i=aux[poz];
  24. if(i==0)
  25. continue;
  26. if(i+l>=L)
  27. break;
  28. if(s[i-1]==s[i+l])
  29. ++nr,aux[sz]=i-1,++sz;
  30. }
  31. sol[l+2]=nr;
  32. }
  33. }
  34.  
  35. int main()
  36. {
  37. ios_base::sync_with_stdio(false);
  38. ifstream f("palpal.in");
  39. f>>s>>k;
  40. f.close();
  41. L=strlen(s);
  42. solve(1);
  43. solve(0);
  44. sol[1]=L;
  45. ofstream g("palpal.out");
  46. for(i=1;i<=k;++i)
  47. g<<sol[i]<<'\n';
  48. g.close();
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement