Submission #1355356


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 (Math.abs(pre - n) == 1) {
                        if (n > pre) {
                            direct = 1;
                        } else {
                            direct = -1;
                        }
                        pre = n;
                    } else {
                        count++;
                        pre = n;
                        direct = 0;
                    }
                } else if (n == (pre + direct)) {
                    pre = n;
                } else {
                    count++;
                    pre = n;
                    direct = 0;                    
                }
            }
       }
        count++;
       return String.valueOf(count);
    }      
}

Submission Info

Submission Time
Task A - Sorted Arrays
User unirita25
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 1842 Byte
Status WA
Exec Time 422 ms
Memory 56632 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 3
AC × 8
WA × 9
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 26068 KB
sample_02.txt AC 159 ms 25808 KB
sample_03.txt AC 161 ms 28244 KB
subtask_1_01.txt WA 397 ms 45116 KB
subtask_1_02.txt WA 348 ms 43868 KB
subtask_1_03.txt WA 319 ms 33520 KB
subtask_1_04.txt WA 400 ms 52820 KB
subtask_1_05.txt WA 407 ms 55584 KB
subtask_1_06.txt WA 406 ms 52948 KB
subtask_1_07.txt WA 410 ms 55676 KB
subtask_1_08.txt AC 406 ms 56632 KB
subtask_1_09.txt WA 422 ms 55856 KB
subtask_1_10.txt AC 162 ms 27860 KB
subtask_1_11.txt WA 167 ms 25044 KB