結果

問題 No.116 門松列(1)
ユーザー matsuyoshi30matsuyoshi30
提出日時 2017-02-03 00:05:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 674 bytes
コンパイル時間 3,575 ms
コンパイル使用メモリ 74,404 KB
実行使用メモリ 55,888 KB
最終ジャッジ日時 2023-09-07 07:07:31
合計ジャッジ時間 6,805 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
55,708 KB
testcase_01 AC 128 ms
55,560 KB
testcase_02 AC 131 ms
55,888 KB
testcase_03 AC 129 ms
55,788 KB
testcase_04 AC 128 ms
55,436 KB
testcase_05 AC 128 ms
55,464 KB
testcase_06 AC 127 ms
55,588 KB
testcase_07 AC 128 ms
55,508 KB
testcase_08 AC 127 ms
55,388 KB
testcase_09 AC 128 ms
55,544 KB
testcase_10 AC 130 ms
55,580 KB
testcase_11 AC 131 ms
55,468 KB
testcase_12 AC 137 ms
55,400 KB
testcase_13 AC 131 ms
55,536 KB
testcase_14 AC 136 ms
55,708 KB
testcase_15 AC 130 ms
55,864 KB
testcase_16 AC 138 ms
55,512 KB
testcase_17 AC 134 ms
55,544 KB
testcase_18 AC 137 ms
55,840 KB
testcase_19 AC 127 ms
55,824 KB
testcase_20 AC 136 ms
55,480 KB
testcase_21 AC 138 ms
55,784 KB
testcase_22 AC 131 ms
55,552 KB
testcase_23 AC 139 ms
55,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = in.nextInt();
        }

        int count = 0;
        for(int i=0; i<n-2; i++) {
            if((a[i+1] < a[i] && a[i] < a[i+2]) || (a[i+1] < a[i+2] && a[i+2] < a[i])) count++;
            if((a[i+2] < a[i] && a[i] < a[i+1]) || (a[i] < a[i+2] && a[i+2] < a[i+1])) count++;
        }

        System.out.println(count);

        in.close();
    }
}
0