14842022-11-13 21:09:11tomi7Völgy (100 pont)cpp11Accepted 100/10039ms6344 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> jobb(n);
	vector<int> bal(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int legnagyobb=-1;
    jobb[n-1]=-1;
	bal[0]=-1;
	for(int i=1;i<n;i++){ 
		for(int j=i-1;1;){ 
		    if(a[i]>a[j]){
			     if(bal[j]==-1){
				     bal[i]=-1;  
					 break;
			     }
			     if(bal[j]!=-1){
				     j=bal[j];
			     }
		    }else{
				bal[i]=j;
				if(i-j>1){
			         legnagyobb=max(i-j, legnagyobb);
				}   
				break;
			}
	    }
	}

	for(int i=n-2;i>=0;i--){
		for(int j=i+1;1;){
	//		cout << "Uj j " << j << '\n';
		    if(a[i]>a[j]){
			     if(jobb[j]==-1){
				     jobb[i]=-1;
	//				 cout << "Elso if : a[i]: " << a[i] << " a[j]: " << a[j] << " jobb[i]: " << jobb[i] << '\n';
					 break;
			     }
			     if(bal[j]!=-1){
				     j=jobb[j];
	//				 cout << "Masodik if : a[i]: " << a[i] << " a[j]: " << a[j] << " jobb[i]: " << jobb[i] << '\n';
			     }
		    }else{
				jobb[i]=j;
				if(j-i>1){
			         legnagyobb=max(j-i, legnagyobb);
				}
	//			cout << "Else : a[i]: " << a[i] << " a[j]: " << a[j] << " jobb[i]: " << jobb[i] << '\n';
				break;
			}
	    }
	}
	cout<<legnagyobb<<'\n';





	
	







	//for(int i=0; i<n; i++) {
	//	cout<<"BAL"<<bal[i]<<" ";
//	}
//	cout<<endl;
//	for(int i=0; i<n; i++) {
//		cout<<"JOBB"<<jobb[i]<<" ";
//	}
//	cout<<endl;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/03ms1684 KiB
2Accepted0/02ms1936 KiB
3Accepted5/52ms2052 KiB
4Accepted5/52ms2260 KiB
5Accepted5/52ms2324 KiB
6Accepted5/52ms2576 KiB
7Accepted5/52ms2776 KiB
8Accepted5/52ms2868 KiB
9Accepted5/52ms3080 KiB
10Accepted5/52ms3288 KiB
11Accepted5/54ms3408 KiB
12Accepted5/54ms3780 KiB
13Accepted5/54ms3728 KiB
14Accepted5/56ms3732 KiB
15Accepted5/534ms5884 KiB
16Accepted5/537ms5880 KiB
17Accepted5/535ms5820 KiB
18Accepted5/535ms5820 KiB
19Accepted5/535ms5824 KiB
20Accepted5/539ms6100 KiB
21Accepted5/539ms6160 KiB
22Accepted5/539ms6344 KiB