Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
- #define INF 0x3f3f3f3f3f
- int main() {
- fastio;
- ll n , flag1 = 0 , flag3 = 0;
- vector<ll> a(100005);
- cin >> n;
- for(ll i = 0; i < n; i++) {
- cin >> a[i];
- if(a[i] == 1) flag1 = 1;
- if(a[i] == 3) flag3 = 1;
- }
- // Finding the maximum alternating depth :
- ll alternate_depth = 1 , best = 1 , last = a[0] , depth = 1;
- if(flag1 == 0 || flag3 == 0) cout << "1 ";
- else {
- for (ll i = 1; i < n; i++) {
- if(a[i] == 3 || a[i] == 1) depth++;
- else if(a[i] == 2 || a[i] == 4) depth--;
- if (a[i] != last && a[i] != 2 && a[i] != 4) {
- last = a[i];
- alternate_depth++;
- best = max(best, alternate_depth);
- }
- else if (a[i] == 2 || a[i] == 4) {
- if(depth == 0) alternate_depth = 0;
- if(depth == 0) last = INF;
- }
- }
- cout << best << " ";
- }
- // Finding the maximum number of elements between any two pairs of ( and ) :
- if(flag1 == 1) {
- ll max1 = 0, total1 = 0, depth1 = 0, maxdepth1 = 0;
- for (ll i = 0; i < n; i++) {
- if (depth1 == 0) total1 = 0;
- total1++;
- if (a[i] == 1) depth1++;
- if (a[i] == 2) depth1--;
- maxdepth1 = max(maxdepth1, total1);
- }
- cout << maxdepth1 << " ";
- }
- else cout << "0 ";
- // Finding the maximum number of elements between any two paris of [ and ] :
- if(flag3 == 1) {
- ll max2 = 0, total2 = 0, depth2 = 0, maxdepth2 = 0;
- for (ll i = 0; i < n; i++) {
- if (depth2 == 0) total2 = 0;
- total2++;
- if (a[i] == 3) depth2++;
- if (a[i] == 4) depth2--;
- maxdepth2 = max(maxdepth2, total2);
- }
- cout << maxdepth2;
- }
- else cout << "0";
- return 0;
- }
Add Comment
Please, Sign In to add comment