Tarango

Shift

Aug 7th, 2016
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.08 KB | None | 0 0
  1. //==================================================================//
  2. // Name        : flash7even                                         //
  3. // Author      : Tarango Khan                                       //
  4. // Codeforces  : flash_7                                            //
  5. // Topcoder    : flash_7                                            //
  6. // Hackerrank  : flash_7                                            //
  7. // Email       : [email protected]                            //
  8. // Facebook    : flash7even                                         //
  9. //==================================================================//
  10.  
  11. //==================================================================//
  12. #include <bits/stdc++.h>                                            //
  13. using namespace std;                                                //
  14. #define read(nm)        freopen(nm, "r", stdin)                     //
  15. #define write(nm)       freopen(nm, "w", stdout)                    //
  16. #define pb              push_back                                   //
  17. #define MP              make_pair                                   //
  18. #define ff              first                                       //
  19. #define ss              second                                      //
  20. #define FABS(x)         ((x)+eps<0?-(x):(x))                        //
  21. #define POPCOUNT        __builtin_popcountll                        //
  22. #define RIGHTMOST       __builtin_ctzll                             //
  23. #define LEFTMOST(x)     (63-__builtin_clzll((x)))                   //
  24. #define NUMDIGIT(x,y)   (((int)(log10((x))/log10((y))))+1)          //
  25. #define SQ(x)           ((x)*(x))                                   //
  26. #define pf              printf                                      //
  27. #define sf              scanf                                       //
  28. #define phl             printf("hello\n")                           //
  29. #define SZ(x)           ((int)(x).size())                           //
  30. #define mems(x,v)       memset(x,v,sizeof(x))                       //
  31. #define CLR(x,y)        memset(x,y,sizeof(x))                       //
  32. #define ALL(x)          (x).begin(),(x).end()                       //
  33. #define NORM(x)         if(x>=mod)x-=mod;                           //
  34. #define MOD(x,y)        (((x)*(y))%mod)                             //
  35. #define fills(v,n)      fill(v.begin(), v.end(), n)                 //
  36. #define LL              long long                                   //
  37. #define LLU             long long unsigned int                      //
  38. #define vlong           long long                                   //
  39. #define uvlong          unsigned long long                          //
  40. #define debug1(v1)      cout<<"1@ Debug Val 1 = "<<v1<<endl;        //
  41. #define debug2(v2)      cout<<"   2@ Debug Num 2 = "<<v2<<endl;     //
  42. #define debug3(v3)      cout<<"      3@ Debug Res 3 = "<<v3<<endl;  //
  43. #define UB(v,a)         upper_bound(v.begin(),v.end(),a)-v.begin()  //
  44. #define LB(v,a)         lower_bound(v.begin(),v.end(),a)-v.begin()  //
  45. #define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)     //
  46. //==================================================================//
  47.  
  48. //==================================================================//
  49. void make_unique(vector<int> &a){ sort(a.begin(), a.end());         //
  50.      a.erase(unique(a.begin(), a.end()), a.end()); }                //
  51. void printDouble(double f,int p){ cout << fixed;                    //
  52.      cout << setprecision(p) << f <<endl; }                         //
  53. int  Set(int N,int cur){ return N = N | (1<<cur); }                 //
  54. int  Reset(int N,int cur){ return N = N & ~(1<<cur); }              //
  55. bool Check(int N,int cur){ return (bool)(N & (1<<cur)); }           //
  56. LL   GCD(LL a,LL b){ if(b == 0) return a; return GCD(b,a%b);}       //
  57. LL   LCM(LL a,LL b){ return a*b/GCD(a,b);}                          //
  58. LL   POW(LL a,LL p){ LL res = 1,x = a;while(p){if(p&1)              //
  59.      res = (res*x); x = (x*x);p >>= 1;} return res;}                //
  60. //==================================================================//
  61.  
  62. //==================================================================//
  63. //int knightDir[8][2] = {{-2,1},{-1,2},{1,2},{2,1},                 //
  64. //                      {2,-1},{-1,-2},{1,-2},{-2,-1}};             //
  65. //int dir8[8][2]      = {{-1,0},{0,1},{1,0},{0,-1},                 //
  66. //                      {-1,-1},{1,1},{1,-1},{-1,1}};               //
  67. //int dir4[4][2]      = {{-1,0},{0,1},{1,0},{0,-1}};                //
  68. //==================================================================//
  69.  
  70. #ifdef forthright48
  71.      #include <ctime>
  72.      clock_t tStart = clock();
  73.      #define debug(args...) {dbg,args; cerr<<endl;}
  74.      #define timeStamp printf("Exc Time: %.2fs\n",(double)(clock()-tStart)/CLOCKS_PER_SEC)
  75. #else
  76.      #define debug(args...)
  77.      #define timeStamp
  78. #endif
  79.  
  80. struct debugger{
  81.     template<typename T> debugger& operator , (const T& v){
  82.         cerr << v << " ";
  83.         return *this;
  84.     }
  85. }dbg;
  86.  
  87. typedef pair <LL,LL> pll;
  88. typedef vector<pll> vll;
  89. typedef vector<LL> vl;
  90.  
  91. const LL inf = 2147383647;
  92. const LL MOD = 1000000007;
  93. const double pi = 2*acos(0.0);
  94. const double eps = 1e-9;
  95. #define Size 100005
  96.  
  97. //=======// Done With The Shortcut Stuffs! Now Let's Code! //=======//
  98.  
  99. int N;
  100. int A[1000005];
  101.  
  102. int maxOccur(){
  103.     if(N == 1) return 1;
  104.     int res = 1,cnt = 1,i = 1;
  105.     while(i<N){
  106.         if(A[i] == A[i-1]){
  107.             cnt++;
  108.         }else{
  109.             res = max(res,cnt);
  110.             cnt = 1;
  111.         }
  112.         i++;
  113.     }
  114.     res = max(res,cnt);
  115.     if(A[0] == A[N-1]){
  116.         cnt = 2;
  117.         i = 1;
  118.         while(i<N){
  119.             if(A[i] != A[i-1]) break;
  120.             i++;
  121.             cnt++;
  122.         }
  123.         i = N-2;
  124.         while(i>=0){
  125.             if(A[i] != A[i+1]) break;
  126.             i--;
  127.             cnt++;
  128.         }
  129.         res = max(res,cnt);
  130.     }
  131.     return res;
  132. }
  133.  
  134. int main() {
  135.     sf("%d",&N);
  136.     for(int i = 0;i<N;i++){
  137.         sf("%d",&A[i]);
  138.     }
  139.     int mxc = maxOccur();
  140.     int res = mxc + (N-mxc)*2;
  141.     cout << res << endl;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment