結果

問題 No.116 門松列(1)
ユーザー tentententen
提出日時 2020-11-10 16:03:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 578 bytes
コンパイル時間 2,002 ms
コンパイル使用メモリ 71,532 KB
実行使用メモリ 56,400 KB
最終ジャッジ日時 2023-09-29 23:38:38
合計ジャッジ時間 6,835 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
56,016 KB
testcase_01 AC 101 ms
55,796 KB
testcase_02 AC 107 ms
55,716 KB
testcase_03 AC 123 ms
56,112 KB
testcase_04 AC 102 ms
55,808 KB
testcase_05 AC 102 ms
55,620 KB
testcase_06 AC 103 ms
56,148 KB
testcase_07 AC 107 ms
55,660 KB
testcase_08 AC 104 ms
56,400 KB
testcase_09 AC 103 ms
55,848 KB
testcase_10 AC 107 ms
55,668 KB
testcase_11 AC 107 ms
56,324 KB
testcase_12 AC 112 ms
55,928 KB
testcase_13 AC 108 ms
55,556 KB
testcase_14 AC 115 ms
56,040 KB
testcase_15 AC 108 ms
55,660 KB
testcase_16 AC 113 ms
56,080 KB
testcase_17 AC 108 ms
55,860 KB
testcase_18 AC 114 ms
55,464 KB
testcase_19 AC 106 ms
55,764 KB
testcase_20 AC 116 ms
56,124 KB
testcase_21 AC 112 ms
55,760 KB
testcase_22 AC 112 ms
55,560 KB
testcase_23 AC 114 ms
56,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < n - 2; i++) {
            if (((arr[i] < arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] > arr[i + 1] && arr[i + 1] < arr[i + 2])) && arr[i] != arr[i + 2]) {
                count++;
            }
        }
        System.out.println(count);
    }
}
0