Guest User

Untitled

a guest
Nov 4th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  5. #define INF 0x3f3f3f3f3f
  6.  
  7. int main() {
  8.  
  9.     fastio;
  10.  
  11.     ll n , flag1 = 0 , flag3 = 0;
  12.     vector<ll> a(100005);
  13.  
  14.     cin >> n;
  15.     for(ll i = 0; i < n; i++) {
  16.         cin >> a[i];
  17.         if(a[i] == 1) flag1 = 1;
  18.         if(a[i] == 3) flag3 = 1;
  19.     }
  20.  
  21.     // Finding the maximum alternating depth :
  22.  
  23.     ll alternate_depth = 1 , best = 1 , last = a[0] , depth = 1;
  24.  
  25.     if(flag1 == 0 || flag3 == 0) cout << "1 ";
  26.     else {
  27.         for (ll i = 1; i < n; i++) {
  28.  
  29.             if(a[i] == 3 || a[i] == 1) depth++;
  30.             else if(a[i] == 2 || a[i] == 4) depth--;
  31.  
  32.             if (a[i] != last && a[i] != 2 && a[i] != 4) {
  33.                 last = a[i];
  34.                 alternate_depth++;
  35.                 best = max(best, alternate_depth);
  36.             }
  37.             else if (a[i] == 2 || a[i] == 4) {
  38.                 if(depth == 0) alternate_depth = 0;
  39.                 if(depth == 0) last = INF;
  40.             }
  41.         }
  42.  
  43.         cout << best << " ";
  44.     }
  45.  
  46.     // Finding the maximum number of elements between any two pairs of ( and ) :
  47.  
  48.     if(flag1 == 1) {
  49.  
  50.         ll max1 = 0, total1 = 0, depth1 = 0, maxdepth1 = 0;
  51.  
  52.         for (ll i = 0; i < n; i++) {
  53.  
  54.             if (depth1 == 0) total1 = 0;
  55.  
  56.             total1++;
  57.  
  58.             if (a[i] == 1) depth1++;
  59.             if (a[i] == 2) depth1--;
  60.  
  61.             maxdepth1 = max(maxdepth1, total1);
  62.  
  63.         }
  64.  
  65.         cout << maxdepth1 << " ";
  66.     }
  67.     else cout << "0 ";
  68.  
  69.     // Finding the maximum number of elements between any two paris of [ and ] :
  70.  
  71.     if(flag3 == 1) {
  72.  
  73.         ll max2 = 0, total2 = 0, depth2 = 0, maxdepth2 = 0;
  74.  
  75.         for (ll i = 0; i < n; i++) {
  76.  
  77.             if (depth2 == 0) total2 = 0;
  78.  
  79.             total2++;
  80.  
  81.             if (a[i] == 3) depth2++;
  82.             if (a[i] == 4) depth2--;
  83.  
  84.             maxdepth2 = max(maxdepth2, total2);
  85.  
  86.         }
  87.  
  88.         cout << maxdepth2;
  89.     }
  90.     else cout << "0";
  91.  
  92.     return 0;
  93. }
Add Comment
Please, Sign In to add comment