結果

問題 No.116 門松列(1)
ユーザー fkwnw3_1243fkwnw3_1243
提出日時 2017-04-29 07:21:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,319 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 73,924 KB
実行使用メモリ 51,364 KB
最終ジャッジ日時 2023-10-11 20:16:29
合計ジャッジ時間 4,775 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 44 ms
49,196 KB
testcase_02 AC 43 ms
49,456 KB
testcase_03 AC 44 ms
49,240 KB
testcase_04 AC 44 ms
49,288 KB
testcase_05 AC 44 ms
49,416 KB
testcase_06 AC 43 ms
49,416 KB
testcase_07 AC 42 ms
49,448 KB
testcase_08 AC 43 ms
49,204 KB
testcase_09 AC 43 ms
49,260 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 44 ms
47,856 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 44 ms
49,428 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 46 ms
49,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int kadomatu = 0;
        int N = Integer.parseInt(reader.readLine());
        String[] inputs = reader.readLine().split(" ");
        for (int i = 0; i < N - 2; i++) {
            int a = Integer.parseInt(inputs[i]);
            int b = Integer.parseInt(inputs[i + 1]);
            int c = Integer.parseInt(inputs[i + 2]);
            if (isKadomatu(a, b, c)) {
                kadomatu += 1;
            }
        }
        System.out.println(kadomatu);
    }

    private static boolean isKadomatu(int a, int b, int c) {

        if (a != b && a != c && b != c) {

            int middle;
            if (a <= b && b <= c) {
                middle = b;
            } else if (b <= a && a <= c) {
                middle = a;
            } else {
                middle = c;
            }

            if (middle == a || middle == c) {
                return true;

            } else {
                return false;
            }

        } else {
            return false;
        }
    }
}
0