結果

問題 No.116 門松列(1)
ユーザー TwinkleStar74TwinkleStar74
提出日時 2017-10-29 16:58:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 739 bytes
コンパイル時間 3,463 ms
コンパイル使用メモリ 74,132 KB
実行使用メモリ 49,708 KB
最終ジャッジ日時 2023-09-07 07:16:31
合計ジャッジ時間 5,298 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,564 KB
testcase_01 AC 43 ms
49,580 KB
testcase_02 AC 44 ms
49,528 KB
testcase_03 AC 43 ms
49,416 KB
testcase_04 AC 44 ms
49,332 KB
testcase_05 AC 44 ms
49,364 KB
testcase_06 AC 44 ms
49,444 KB
testcase_07 AC 43 ms
49,472 KB
testcase_08 AC 44 ms
49,276 KB
testcase_09 AC 43 ms
49,268 KB
testcase_10 AC 44 ms
49,432 KB
testcase_11 AC 45 ms
49,336 KB
testcase_12 AC 44 ms
49,344 KB
testcase_13 AC 44 ms
49,136 KB
testcase_14 AC 45 ms
49,472 KB
testcase_15 AC 44 ms
49,452 KB
testcase_16 AC 44 ms
49,248 KB
testcase_17 AC 44 ms
49,708 KB
testcase_18 AC 44 ms
49,332 KB
testcase_19 AC 43 ms
47,436 KB
testcase_20 AC 44 ms
49,384 KB
testcase_21 AC 45 ms
49,516 KB
testcase_22 AC 44 ms
49,472 KB
testcase_23 AC 44 ms
49,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class No116 {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] str = br.readLine().split(" ");
		int[] num = new int[n];
		for(int i=0; i < n; i++) num[i] = Integer.parseInt(str[i]);
		System.out.println(judge(num));
	}
	
	public static int judge(int[] a){
		int ans = 0;
		for(int i=1; i < a.length - 1; i++){
			if(a[i-1] != a[i] && a[i-1] != a[i+1] && a[i] != a[i+1]){
				if(!(a[i-1] > a[i] && a[i] > a[i+1]) && !(a[i-1] < a[i] && a[i] < a[i+1])){
					ans++;
				}
			}
		}
		return ans;
	}
}
0