結果

問題 No.116 門松列(1)
ユーザー r.suzukir.suzuki
提出日時 2016-01-04 14:34:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 977 bytes
コンパイル時間 3,271 ms
コンパイル使用メモリ 74,312 KB
実行使用メモリ 55,928 KB
最終ジャッジ日時 2023-09-07 06:53:28
合計ジャッジ時間 7,674 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
55,800 KB
testcase_01 AC 131 ms
55,760 KB
testcase_02 AC 132 ms
55,548 KB
testcase_03 AC 134 ms
55,652 KB
testcase_04 AC 131 ms
55,584 KB
testcase_05 AC 130 ms
55,636 KB
testcase_06 AC 130 ms
55,764 KB
testcase_07 AC 128 ms
55,580 KB
testcase_08 AC 129 ms
55,424 KB
testcase_09 AC 129 ms
55,860 KB
testcase_10 AC 132 ms
55,628 KB
testcase_11 AC 129 ms
55,644 KB
testcase_12 AC 137 ms
55,660 KB
testcase_13 AC 129 ms
55,640 KB
testcase_14 AC 138 ms
55,640 KB
testcase_15 AC 133 ms
55,524 KB
testcase_16 AC 135 ms
55,928 KB
testcase_17 AC 134 ms
55,604 KB
testcase_18 AC 142 ms
55,552 KB
testcase_19 AC 138 ms
55,780 KB
testcase_20 AC 139 ms
55,416 KB
testcase_21 AC 140 ms
55,516 KB
testcase_22 AC 132 ms
55,476 KB
testcase_23 AC 138 ms
55,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

public class No_116 {
	static int kadomatsu;

	static void countKadomatsu(int[] array, int i) {
		if (i + 1 >= array.length) {
			return;
		}
		int left = array[i - 1];
		int right = array[i + 1];
		int[] newArray = { array[i - 1], array[i], array[i + 1] };
		for (int j = 0; j < newArray.length - 1; j++) {
			for (int k = j + 1; k < newArray.length; k++) {
				if (newArray[j] > newArray[k]) {
					int tmp = newArray[j];
					newArray[j] = newArray[k];
					newArray[k] = tmp;
				}
			}
		}

		if ((newArray[1] == left || newArray[1] == right)
				&& (newArray[0] != newArray[1] && newArray[1] != newArray[2])) {
			kadomatsu++;
		}
		countKadomatsu(array, ++i);
	}

	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int num = sc.nextInt();
		int[] array = new int[num];

		for (int i = 0; i < num; i++) {
			array[i] = sc.nextInt();
		}

		countKadomatsu(array, 1);
		System.out.println(kadomatsu);
		sc.close();

	}

}
0