14832022-11-13 21:07:47tomi7Völgy (100 pont)cpp11Wrong answer 85/10039ms6160 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/03ms1812 KiB
2Accepted0/02ms2068 KiB
3Accepted5/52ms2236 KiB
4Accepted5/52ms2408 KiB
5Accepted5/52ms2484 KiB
6Accepted5/52ms2488 KiB
7Wrong answer0/52ms2484 KiB
8Accepted5/52ms2612 KiB
9Wrong answer0/52ms2700 KiB
10Accepted5/52ms2708 KiB
11Accepted5/54ms3008 KiB
12Accepted5/54ms3008 KiB
13Accepted5/54ms3012 KiB
14Accepted5/56ms3268 KiB
15Accepted5/534ms5364 KiB
16Accepted5/537ms5772 KiB
17Wrong answer0/535ms5524 KiB
18Accepted5/535ms5712 KiB
19Accepted5/537ms5788 KiB
20Accepted5/539ms5988 KiB
21Accepted5/539ms5884 KiB
22Accepted5/539ms6160 KiB