Submission #1355369


Source Code Expand

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 *
 * @author 97797
 */
public class Main {
    public static void main(String[] args) throws IOException {
        System.out.println(new Main().run(args, System.in));
    }
    public String run(String[] args, InputStream in) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        long N = Long.valueOf(reader.readLine());
        String[] val = reader.readLine().replaceAll("\\s+", " ").split(" ");
        List<Integer> list = Stream.of(val).map(Integer::parseInt).collect(Collectors.toList());

        int direct = 0;
        int pre = 0;
        int count = 0;
        for (Integer n : list) {
            if (pre == 0) {
                pre = n;
            } else {
                if (pre == n) {
                    // nop;
                } else {
                    if (direct == 0) {
                        if (n > pre) {
                            direct = 1;
                        } else {
                            direct = -1;
                        }
                    } else if (direct > 0) {
                        if (n > pre) {
                            //
                        } else {
                            count++;
                            direct = 0;                    
                        }
                    } else {//direct < 0
                        if (pre > n) {
                            //
                        } else {
                            count++;
                            direct = 0;                    
                        }
                    }
                    pre = n;
                }
            }
       }
        count++;
       return String.valueOf(count);
    }      
}

Submission Info

Submission Time
Task A - Sorted Arrays
User unirita25
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 2009 Byte
Status AC
Exec Time 441 ms
Memory 55512 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 157 ms 24404 KB
sample_02.txt AC 163 ms 24916 KB
sample_03.txt AC 165 ms 24660 KB
subtask_1_01.txt AC 354 ms 42828 KB
subtask_1_02.txt AC 363 ms 42336 KB
subtask_1_03.txt AC 305 ms 31768 KB
subtask_1_04.txt AC 441 ms 52164 KB
subtask_1_05.txt AC 416 ms 52732 KB
subtask_1_06.txt AC 386 ms 52924 KB
subtask_1_07.txt AC 399 ms 55104 KB
subtask_1_08.txt AC 408 ms 55512 KB
subtask_1_09.txt AC 408 ms 53180 KB
subtask_1_10.txt AC 164 ms 24016 KB
subtask_1_11.txt AC 161 ms 26068 KB