結果

問題 No.116 門松列(1)
ユーザー YOSHI
提出日時 2021-03-01 19:15:30
言語 Java
(openjdk 23)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 834 bytes
コンパイル時間 3,946 ms
コンパイル使用メモリ 79,720 KB
実行使用メモリ 37,908 KB
最終ジャッジ日時 2024-10-03 00:56:39
合計ジャッジ時間 6,323 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Stream;

public class No00000116_Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int[] arr = Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();

		int cnt = 0;
		for(int i = 1; i < n - 1; i++) {
			cnt += check(arr[i - 1], arr[i], arr[i + 1]);
		}

		System.out.println(cnt);

	}

	private static int check(int num1, int num2, int num3) {
		if(num1 == num2 || num2 == num3 || num3 == num1) {
			return 0;
		}
		if(Math.max(Math.max(num1, num2), num3) == num2
				|| Math.min(Math.min(num1, num2), num3) == num2) {
			return 1;
		}
		return 0;
	}

}
0