結果

問題 No.116 門松列(1)
ユーザー takeya_okino
提出日時 2017-06-23 06:38:05
言語 Java
(openjdk 23)
結果
AC  
実行時間 143 ms / 5,000 ms
コード長 600 bytes
コンパイル時間 2,060 ms
コンパイル使用メモリ 74,260 KB
実行使用メモリ 54,312 KB
最終ジャッジ日時 2024-06-25 01:30:00
合計ジャッジ時間 5,909 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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