結果

問題 No.116 門松列(1)
ユーザー yagi2
提出日時 2017-04-25 11:01:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 932 bytes
コンパイル時間 2,440 ms
コンパイル使用メモリ 87,840 KB
実行使用メモリ 41,856 KB
最終ジャッジ日時 2024-06-25 01:27:42
合計ジャッジ時間 6,458 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        List<Integer> A = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            A.add(Integer.parseInt(sc.next()));
        }

        int cnt = 0;
        for (int i = 0; i < N - 2; i++) {
            if (isKadomatsu(A.get(i), A.get(i + 1), A.get(i + 2))) cnt++;
        }

        System.out.println(cnt);
    }

    private static boolean isKadomatsu(int a, int b, int c) {
        List<Integer> K = new ArrayList<>();
        K.add(a); K.add(b); K.add(c);
        K.sort((o1, o2) -> {
            if (o1 > o2) return -1;
            if (o1 < o2) return 1;
            return 0;
        });
        return (K.get(1) == a || K.get(1) == c) && (a != b && a != c && b != c);
    }
}
0