Submission #1221485


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
# define INF 0x3f3f3f3f
#define pb push_back
#define mk make_pair
#define vp vector<pair<ll,ll> >
#define se second
#define fi first
#define vi vector<ll>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
#define rep(i,n) for(ll i=0;i<n;i++)
#define fab(i,a,b) for(ll i=a;i<=b;i++)
#define inp(n,a) for(ll i=0;i<n;i++){cin>>a[i];}
#define strToInt(x,z) istringstream y(x);y>>z  //(string,integer)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b / __gcd(a,b);
#define MOD 1000000007
#define pi 3.14159265

ll a[1000010],n;
int inc(int pos)
{
    for(int i = pos+1; i <= n ; i ++)
    {
        if(a[i] < a[i-1])
        {
            return i-1;
        }
    }
}

int dec(int pos)
{
    for(int i = pos+1; i <= n ; i ++)
        {
            if(a[i] > a[i-1])
            {
                return i-1;
            }
        }
}

int main()
{
	ll j=0;
    cin >> n;

    fab(i,1,n)cin >> a[i];
    int cnt = 0;
    while(j<n)
    {
        j = max(inc(j+1),dec(j+1));
        //DEBUG(j);
        cnt++;
    }

    cout << cnt <<endl;


    return 0;
}

Submission Info

Submission Time
Task A - Sorted Arrays
User zerocool
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1250 Byte
Status TLE
Exec Time 2103 ms
Memory 1024 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
TLE × 3
TLE × 17
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt
Case Name Status Exec Time Memory
sample_01.txt TLE 2103 ms 256 KB
sample_02.txt TLE 2103 ms 256 KB
sample_03.txt TLE 2103 ms 256 KB
subtask_1_01.txt TLE 2103 ms 768 KB
subtask_1_02.txt TLE 2103 ms 640 KB
subtask_1_03.txt TLE 2103 ms 512 KB
subtask_1_04.txt TLE 2103 ms 1024 KB
subtask_1_05.txt TLE 2103 ms 1024 KB
subtask_1_06.txt TLE 2103 ms 1024 KB
subtask_1_07.txt TLE 2103 ms 1024 KB
subtask_1_08.txt TLE 2103 ms 1024 KB
subtask_1_09.txt TLE 2103 ms 1024 KB
subtask_1_10.txt TLE 2103 ms 256 KB
subtask_1_11.txt TLE 2103 ms 256 KB