Submission #1369609


Source Code Expand

#include <bits/stdc++.h>

#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 100100;
const long long MX = sqrt(N);
const long long H = 17;
const long long MAGIC = 1000;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int a[N];

bool f(int a, int b, int c)
{
        return (a <= b && b <= c || a >= b && b >= c);
}

void solve()
{
        int cnt = 0;
        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        for(int i = 1; i <= n; i++){
                int co = 0;
                vector < int > v;
                for(int j = i; j <= n; j++){
                        if(!v.empty()){
                                if(v.back() < a[j]){
                                        co |= 1;
                                }
                                if(v.back() > a[j]){
                                        co |= 2;
                                }
                        }
                        v.pb(a[j]);
                        if(co == 3){
                                cnt++;
                                i = j - 1;
                                break;
                        }
                        if(j == n){
                                i = j;
                        }
                }
        }
        cout << cnt + 1 << endl;
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("landscape.in");
        //fout("landscape.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}

Submission Info

Submission Time
Task A - Sorted Arrays
User EliteWantsYou
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1889 Byte
Status AC
Exec Time 17 ms
Memory 1276 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 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 AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask_1_01.txt AC 11 ms 512 KB
subtask_1_02.txt AC 6 ms 896 KB
subtask_1_03.txt AC 5 ms 384 KB
subtask_1_04.txt AC 17 ms 640 KB
subtask_1_05.txt AC 12 ms 1276 KB
subtask_1_06.txt AC 17 ms 640 KB
subtask_1_07.txt AC 17 ms 640 KB
subtask_1_08.txt AC 12 ms 1276 KB
subtask_1_09.txt AC 16 ms 640 KB
subtask_1_10.txt AC 1 ms 256 KB
subtask_1_11.txt AC 1 ms 256 KB