Advertisement
a53

PlatouAT

a53
Apr 9th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define maxN 1111115
  3. using namespace std;
  4. int findval(long long pos,long long putere)
  5. {
  6. if(pos==1)
  7. return 1;
  8. if(putere==4)
  9. {
  10. if(pos==1) return 1;
  11. if(pos==2) return 0;
  12. if(pos==3) return 0;
  13. if(pos==4) return 1;
  14. }
  15. long long aux=putere/4;
  16. if(1<=pos && pos<=aux)
  17. return findval(pos,putere/4);
  18. if(aux<pos && pos<=aux*2)
  19. return 1-findval(pos-aux,putere/4);
  20. if(aux*2<pos && pos<=aux*3)
  21. return 1-findval(pos-2*aux,putere/4);
  22. if(aux*3<pos && pos<=aux*4)
  23. return findval(pos-3*aux,putere/4);
  24. }
  25. char caracter(long long n)
  26. {
  27. char c;
  28. long long putere=1;
  29. while(putere<=n)
  30. putere*=4;
  31. if(putere==4*n)
  32. putere/=4;
  33. int aux=findval(n,putere);
  34. if(aux==1)
  35. c='A';
  36. else c='T';
  37. return c;
  38. }
  39. inline bool putere(long long x)
  40. {
  41. return !(x&(x-1));
  42. }
  43. int main()
  44. {
  45. int n;
  46. cin>>n;
  47. char actual,precedent='$';
  48. long long len=0;
  49. long long maxx=-1;
  50. for(int i=1;i<=n;i++)
  51. {
  52. long long x;
  53. cin>>x;
  54. actual=caracter(x);
  55. if(actual=='T' && precedent=='T')
  56. len++;
  57. else
  58. {
  59. if(putere(len+1)&&precedent=='T')
  60. maxx=max(maxx,len);
  61. if(actual=='T')
  62. len=1;
  63. else len=0;
  64. }
  65. precedent=actual;
  66. }
  67. if(maxx==-1)
  68. cout<<"NU EXISTA";
  69. else
  70. cout<<maxx;
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement