結果

問題 No.116 門松列(1)
ユーザー Grenache
提出日時 2015-09-23 20:22:29
言語 Java
(openjdk 23)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 801 bytes
コンパイル時間 3,191 ms
コンパイル使用メモリ 77,028 KB
実行使用メモリ 54,292 KB
最終ジャッジ日時 2024-06-25 01:10:58
合計ジャッジ時間 7,150 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder116 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
        	a[i] = sc.nextInt();
        }

        int ret = 0;
        for (int i = 1; i <= n - 2; i++) {
        	if (isKadomatu(a, i)) {
        		ret++;
        	}
        }
        
        System.out.println(ret);
        
        sc.close();
    }

	private static boolean isKadomatu(int[] a, int i) {
		if (a[i - 1] == a[i] || a[i] == a[i + 1] || a[i - 1] == a[i + 1]) {
			return false;
		}
		if (a[i] > a[i - 1] && a[i] > a[i + 1]) {
			return true;
		}
		if (a[i] < a[i - 1] && a[i] < a[i + 1]) {
			return true;
		}
		
		return false;
	}
}
0