14662022-10-24 04:31:52tomi7Völgy (100 pont)cpp11Wrong answer 85/10039ms6904 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=0;
    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
base85/100
1Accepted0/03ms1816 KiB
2Accepted0/02ms2060 KiB
3Accepted5/52ms2264 KiB
4Accepted5/52ms2412 KiB
5Accepted5/52ms2656 KiB
6Accepted5/52ms2864 KiB
7Wrong answer0/52ms2940 KiB
8Accepted5/52ms3056 KiB
9Wrong answer0/52ms3220 KiB
10Accepted5/52ms3328 KiB
11Accepted5/54ms3708 KiB
12Accepted5/54ms3928 KiB
13Accepted5/54ms4136 KiB
14Accepted5/56ms4388 KiB
15Accepted5/534ms6568 KiB
16Accepted5/537ms6776 KiB
17Wrong answer0/535ms6848 KiB
18Accepted5/535ms6808 KiB
19Accepted5/535ms6808 KiB
20Accepted5/539ms6904 KiB
21Accepted5/539ms6860 KiB
22Accepted5/539ms6756 KiB