結果

問題 No.116 門松列(1)
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-23 06:38:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 600 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 71,292 KB
実行使用メモリ 57,880 KB
最終ジャッジ日時 2023-09-07 07:12:00
合計ジャッジ時間 6,494 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
55,640 KB
testcase_01 AC 128 ms
56,104 KB
testcase_02 AC 127 ms
55,696 KB
testcase_03 AC 123 ms
55,392 KB
testcase_04 AC 123 ms
55,744 KB
testcase_05 AC 125 ms
55,808 KB
testcase_06 AC 128 ms
55,796 KB
testcase_07 AC 125 ms
55,576 KB
testcase_08 AC 125 ms
56,116 KB
testcase_09 AC 126 ms
55,724 KB
testcase_10 AC 128 ms
55,812 KB
testcase_11 AC 126 ms
55,700 KB
testcase_12 AC 136 ms
53,496 KB
testcase_13 AC 127 ms
55,744 KB
testcase_14 AC 135 ms
55,616 KB
testcase_15 AC 129 ms
55,620 KB
testcase_16 AC 135 ms
55,564 KB
testcase_17 AC 130 ms
55,700 KB
testcase_18 AC 136 ms
55,444 KB
testcase_19 AC 127 ms
55,860 KB
testcase_20 AC 139 ms
55,836 KB
testcase_21 AC 135 ms
55,696 KB
testcase_22 AC 129 ms
55,700 KB
testcase_23 AC 136 ms
57,880 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[] a = new int[N];
    for(int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
    }
    int ans = 0;
    for(int i = 0; i < N - 2; i++) {
      if(a[i] != a[i + 1] && a[i] != a[i + 2] && a[i + 1] != a[i + 2]) {
        int max = Math.max(a[i], Math.max(a[i + 1], a[i + 2]));
        int min = Math.min(a[i], Math.min(a[i + 1], a[i + 2]));
        if(a[i + 1] == max || a[i + 1] == min) ans++;
      }
    }
    System.out.println(ans);
  }
}
0