結果

問題 No.116 門松列(1)
ユーザー tsunabittsunabit
提出日時 2018-05-01 03:21:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 2,066 bytes
コンパイル時間 4,799 ms
コンパイル使用メモリ 76,880 KB
実行使用メモリ 55,876 KB
最終ジャッジ日時 2023-09-07 07:23:08
合計ジャッジ時間 7,912 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,500 KB
testcase_01 AC 124 ms
55,612 KB
testcase_02 AC 124 ms
55,848 KB
testcase_03 AC 127 ms
55,548 KB
testcase_04 AC 129 ms
55,800 KB
testcase_05 AC 131 ms
55,604 KB
testcase_06 AC 125 ms
55,384 KB
testcase_07 AC 127 ms
55,552 KB
testcase_08 AC 129 ms
55,600 KB
testcase_09 AC 127 ms
55,512 KB
testcase_10 AC 130 ms
55,876 KB
testcase_11 AC 130 ms
55,668 KB
testcase_12 AC 126 ms
55,388 KB
testcase_13 AC 124 ms
55,504 KB
testcase_14 AC 126 ms
55,668 KB
testcase_15 AC 125 ms
55,808 KB
testcase_16 AC 126 ms
55,592 KB
testcase_17 AC 129 ms
55,680 KB
testcase_18 AC 126 ms
55,508 KB
testcase_19 AC 128 ms
55,532 KB
testcase_20 AC 127 ms
55,660 KB
testcase_21 AC 128 ms
55,504 KB
testcase_22 AC 124 ms
55,612 KB
testcase_23 AC 128 ms
55,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.stream.Stream;

// ***問題文***
// あけましておめでとうございます。
// 玄関に飾る門松を作っている時に、あることに気づいた。
// N本の竹を無作為に並べた時の高さをそれぞれAiとしたときに、
// 順番を変えずに連続になった3本を取り出した時に、何組の組み合わせが「門松列」になっているかを知りたくなった。
// 門松とは、選んだ「3つの竹の長さの降順で2番目が、左または右側になっているもの」らしいのですが、
// ここでさらに、「3つの長さはすべて異なる」という条件も満たすものを「門松列」とする。
// N本の竹の高さが与えられるので、「門松列」になる組み合わせ数を求めてください。
// それぞれの竹は番号が振ってあるので区別ができるとする。
// ***入力***
// N
// A1 A2…AN
// 入力は全て整数で与えられる。
// 3≤N≤100=102
// 1≤Ai≤100=102,1≤i≤N
// ***出力***
// 門松列になる組み合わせ数を出力してください。最後に改行してください。

public class No116 {
    public static void main(String[] args) {
        // 標準入力から読み込む際に、Scannerオブジェクトを使う。
        Scanner sc = new Scanner(System.in);
        // 2行目をnextLineで読み込むため、数値もnextLineで読み込む
        int n = Integer.parseInt(sc.nextLine());
        // 新しいstreamを作成し、各要素をintに変換
        int[] a = Stream.of(sc.nextLine().split(" " , 0)).mapToInt(Integer::parseInt).toArray();
        int count = 0;
        for(int i = 0; i < a.length -2; i++) {
            if(((a[i] != a[i + 1]) && (a[i + 1] != a[i + 2]) && (a[i] != a[i + 2]) )
             && !((a[i] < a[i + 1]) && (a[i + 1] < a[i + 2]))
             && !((a[i] > a[i + 1]) && (a[i + 1] > a[i + 2]))) {
                 count++;
             }
        }
        System.out.println(count);
    }
}
0