50832023-04-15 16:52:51AncsaLegmesszebbi rossz sorrendű (35 pont)cpp11Time limit exceeded 31/35254ms5308 KiB
#include <bits/stdc++.h>
//Nemes Tihamer orszagos feladat
//Tesztelheto
//https://njudge.hu/problemset/main/NT23_Legmesszebbi/

using namespace std;
/*
be
10
7 2 4 17 6 5 10 10 18 19
ki
i 6
*/

/*
be
12
2 4 7 11 9 6 3 2 8 4 6 10

ki
3 11

*/


int main()
{
    srand(time(0));
    int n;
    cin>>n;
    vector<int> a(n);
    int eleje=0, vege=0,uj;
    bool novekvo=true;
    for(int i=0;i<n;i++)
    {
        cin>>a.at(i);
  /*      if (i<n/2)
           a.at(i)=rand()%500;
        else
           a.at(i)=rand()%1000;*/
        if(a.at(i)<a.at(0))
        {
            vege=i;
        }
        //if (i!=0 && novekvo && a.at(i)<a.at(i-1))
        //    novekvo=false;
    }
    /*if (novekvo)
    {
        cout<<-1;
    }
*/    int kicsi=a.at(0);
/*
    for(int i=0;i<n;i++)
    {
        cout<<a.at(i)<<"\t";
        if(i%10==9)
            cout<<endl;
    }
*/
    int tav=vege;
    //cout<<vege<<endl;
    for(int i=1;i<n-tav;i++)
    {
        int j=n-1;
        bool talalt=false;
        //cout<<"kicsi:"<<kicsi<<endl;
        if (a.at(i)>kicsi)
        {
           kicsi=a.at(i);
           while(j>=i+tav+1 && !talalt)
           {
//              cout<<"lepes:"<<i<<" "<<j<<" "<<tav<<endl;
              if(a.at(j)<a.at(i))
              {
                eleje=i;
                vege=j;
                tav=j-i;
                talalt=true;

        //        cout<<eleje<<" "<<vege<<endl;
              }
              j--;
           }
        }
    }

    if (eleje==0 && vege==0)
        cout<<-1;
    else
        cout << eleje+1<<" "<<vege+1 << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base31/35
1Accepted0/03ms1960 KiB
2Accepted0/086ms2816 KiB
3Accepted1/13ms2324 KiB
4Accepted1/13ms2540 KiB
5Accepted1/12ms2648 KiB
6Accepted1/13ms2868 KiB
7Accepted1/13ms2996 KiB
8Accepted1/13ms3244 KiB
9Accepted1/14ms3424 KiB
10Accepted1/14ms3640 KiB
11Accepted1/14ms3800 KiB
12Accepted2/2109ms4352 KiB
13Accepted2/2136ms4316 KiB
14Accepted2/2152ms4508 KiB
15Accepted2/264ms4528 KiB
16Accepted2/2165ms4528 KiB
17Accepted2/248ms4656 KiB
18Accepted2/259ms4656 KiB
19Accepted2/270ms4956 KiB
20Accepted2/272ms5180 KiB
21Accepted2/286ms5308 KiB
22Accepted2/287ms5264 KiB
23Time limit exceeded0/2254ms4220 KiB
24Time limit exceeded0/2247ms4108 KiB