結果

問題 No.116 門松列(1)
コンテスト
ユーザー YOSHI
提出日時 2021-03-01 19:15:30
言語 Java
(openjdk 26.0.2.1 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 37 ms / 5,000 ms
+ 341µs
コード長 834 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,598 ms
コンパイル使用メモリ 88,976 KB
実行使用メモリ 40,748 KB
最終ジャッジ日時 2026-09-09 07:56:57
合計ジャッジ時間 5,073 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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