Submission #1793430


Source Code Expand

#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n;
int a[100005];
bool upflag = false;
bool downflag = false;
int ans = 1;
int pre;
/**********************************************/

int main(){
    cin >> n;
    REP(i, n){
        cin >> a[i];
    }
    
    pre = a[0];
    FOR(i, 1, n){
        if(!upflag && !downflag){
            if(pre < a[i]) upflag = true;
            else if(pre > a[i]) downflag = true;
        }else if(upflag){
            if(pre > a[i]){
                upflag = false;
                ans++;
            }
        }else{
            if(pre < a[i]){
                downflag = false;
                ans++;
            }
        }
        pre = a[i];
    }
    
    cout << ans << endl;
}

Submission Info

Submission Time
Task A - Sorted Arrays
User wheson
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1546 Byte
Status AC
Exec Time 54 ms
Memory 640 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 33 ms 512 KB
subtask_1_02.txt AC 26 ms 384 KB
subtask_1_03.txt AC 17 ms 384 KB
subtask_1_04.txt AC 54 ms 640 KB
subtask_1_05.txt AC 53 ms 640 KB
subtask_1_06.txt AC 54 ms 640 KB
subtask_1_07.txt AC 54 ms 640 KB
subtask_1_08.txt AC 54 ms 640 KB
subtask_1_09.txt AC 54 ms 640 KB
subtask_1_10.txt AC 1 ms 256 KB
subtask_1_11.txt AC 1 ms 256 KB