Submission #2242308


Source Code Expand

/*
 * 長さ N の配列 A が与えられます。 A を何箇所かで切って、A の連続した部分であるようないくつかの数列に分けます。
 * この時、分けられたあとの数列は全て、単調非減少または単調非増加な列になっている必要があります。 最小で何個の数列に分ければ良いかを求めて下さい。
 */

import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int n = Integer.parseInt(sc.next());
            int temp1, temp2, index = 0, count = 0;
            
            temp2 = Integer.parseInt(sc.next());
            
            while(index<n-1){
            	temp1 = temp2;
            	temp2 = Integer.parseInt(sc.next());
            	index++;
            	
            	while(index<n-1 && temp2 == temp1){
            		temp2 = Integer.parseInt(sc.next());
            		index++;
            	}
            	
            	if(temp1 < temp2){
            		while(index<n-1 && temp1 <= temp2){
            			temp1 = temp2;
            			temp2 = Integer.parseInt(sc.next());
            			index++;
            		}
            		if(index==n-1 && temp1 > temp2){
            			count++;
            		}
            	}else{
            		while(index<n-1 && temp1 >= temp2){
            			temp1 = temp2;
            			temp2 = Integer.parseInt(sc.next());
            			index++;
            		}
            		if(index==n-1 && temp1 < temp2){
            			count++;
            		}
            	}
            	count++;
            }
            
            //出力
            System.out.println(Math.max(count, 1));
            sc.close();
        }
    }
	

Submission Info

Submission Time
Task A - Sorted Arrays
User kogumakoguma
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 1818 Byte
Status AC
Exec Time 364 ms
Memory 46588 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 91 ms 21584 KB
sample_02.txt AC 89 ms 20692 KB
sample_03.txt AC 91 ms 21716 KB
subtask_1_01.txt AC 313 ms 41976 KB
subtask_1_02.txt AC 272 ms 39320 KB
subtask_1_03.txt AC 237 ms 34280 KB
subtask_1_04.txt AC 354 ms 43848 KB
subtask_1_05.txt AC 356 ms 45568 KB
subtask_1_06.txt AC 351 ms 44844 KB
subtask_1_07.txt AC 355 ms 42488 KB
subtask_1_08.txt AC 364 ms 46588 KB
subtask_1_09.txt AC 351 ms 46520 KB
subtask_1_10.txt AC 89 ms 19028 KB
subtask_1_11.txt AC 90 ms 21332 KB