Submission #1306709


Source Code Expand

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int[] A = new int[N];
        int ans = 1;
        int sign = 0;
        for (int i = 0; i < N; ++i) {
            A[i] = sc.nextInt();

            if (i > 0 && A[i - 1] != A[i]) {
                if (sign == 0) {
                    sign = (A[i - 1] < A[i]) ? 1 : -1;
                } else if (sign == -1) {
                    if (A[i - 1] < A[i]) {
                        sign = 0;
                        ++ans;
                    }
                } else {
                    if (A[i - 1] > A[i]) {
                        sign = 0;
                        ++ans;
                    }
                }
            }
        }

        _out.println(ans);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Submission Info

Submission Time
Task A - Sorted Arrays
User hhelibex
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 2139 Byte
Status AC
Exec Time 481 ms
Memory 50236 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 92 ms 19028 KB
sample_02.txt AC 93 ms 21588 KB
sample_03.txt AC 91 ms 19796 KB
subtask_1_01.txt AC 406 ms 45684 KB
subtask_1_02.txt AC 374 ms 42916 KB
subtask_1_03.txt AC 302 ms 39424 KB
subtask_1_04.txt AC 452 ms 46504 KB
subtask_1_05.txt AC 464 ms 46560 KB
subtask_1_06.txt AC 459 ms 50236 KB
subtask_1_07.txt AC 462 ms 47224 KB
subtask_1_08.txt AC 481 ms 48264 KB
subtask_1_09.txt AC 465 ms 50236 KB
subtask_1_10.txt AC 91 ms 19924 KB
subtask_1_11.txt AC 91 ms 21844 KB