結果

問題 No.116 門松列(1)
ユーザー GrenacheGrenache
提出日時 2015-09-23 20:22:29
言語 Java19
(openjdk 21)
結果
AC  
実行時間 150 ms / 5,000 ms
コード長 801 bytes
コンパイル時間 5,777 ms
コンパイル使用メモリ 75,068 KB
実行使用メモリ 57,680 KB
最終ジャッジ日時 2023-09-07 06:50:00
合計ジャッジ時間 8,494 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
55,588 KB
testcase_01 AC 137 ms
55,632 KB
testcase_02 AC 137 ms
55,504 KB
testcase_03 AC 138 ms
55,716 KB
testcase_04 AC 137 ms
55,540 KB
testcase_05 AC 139 ms
55,664 KB
testcase_06 AC 140 ms
55,588 KB
testcase_07 AC 138 ms
55,640 KB
testcase_08 AC 135 ms
55,576 KB
testcase_09 AC 142 ms
55,332 KB
testcase_10 AC 138 ms
55,644 KB
testcase_11 AC 135 ms
55,424 KB
testcase_12 AC 150 ms
55,632 KB
testcase_13 AC 136 ms
55,528 KB
testcase_14 AC 144 ms
55,620 KB
testcase_15 AC 138 ms
55,672 KB
testcase_16 AC 145 ms
55,456 KB
testcase_17 AC 140 ms
55,652 KB
testcase_18 AC 146 ms
55,648 KB
testcase_19 AC 137 ms
55,648 KB
testcase_20 AC 143 ms
55,652 KB
testcase_21 AC 142 ms
55,352 KB
testcase_22 AC 133 ms
55,572 KB
testcase_23 AC 149 ms
57,680 KB
権限があれば一括ダウンロードができます

ソースコード

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