結果

問題 No.116 門松列(1)
ユーザー koukonkokoukonko
提出日時 2015-12-11 23:11:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 931 bytes
コンパイル時間 2,805 ms
コンパイル使用メモリ 74,124 KB
実行使用メモリ 56,292 KB
最終ジャッジ日時 2023-09-07 06:53:14
合計ジャッジ時間 6,396 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
55,416 KB
testcase_01 AC 123 ms
55,408 KB
testcase_02 AC 125 ms
56,032 KB
testcase_03 AC 126 ms
55,652 KB
testcase_04 AC 123 ms
55,344 KB
testcase_05 AC 123 ms
55,556 KB
testcase_06 AC 124 ms
55,636 KB
testcase_07 AC 123 ms
55,580 KB
testcase_08 AC 124 ms
55,748 KB
testcase_09 AC 125 ms
55,784 KB
testcase_10 AC 127 ms
55,772 KB
testcase_11 AC 123 ms
56,292 KB
testcase_12 AC 127 ms
55,556 KB
testcase_13 AC 126 ms
55,636 KB
testcase_14 AC 131 ms
55,504 KB
testcase_15 AC 125 ms
55,412 KB
testcase_16 AC 133 ms
55,632 KB
testcase_17 AC 126 ms
55,552 KB
testcase_18 AC 133 ms
55,600 KB
testcase_19 AC 122 ms
55,356 KB
testcase_20 AC 127 ms
55,480 KB
testcase_21 AC 135 ms
56,284 KB
testcase_22 AC 129 ms
55,396 KB
testcase_23 AC 133 ms
55,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		try {
			Scanner scan = new Scanner(System.in);
			int count = scan.nextInt();

			int[] height = new int[count];
			for (int i = 0; i < count; ++i) {
				height[i] = scan.nextInt();
			}

			int ans = 0;
			for (int i = 1; i < count - 1; ++i) {
				int max = 0, min = 101;
				boolean flag = false;
				for (int j = -1; j < 2; ++j) {
					if (max == height[i + j] || min == height[i + j]) {
						flag = true;
						break;
					}
					if (max < height[i + j]) {
						max = height[i + j];
					}
					if (min > height[i + j]) {
						min = height[i + j];
					}
				}
				if (flag) {
					continue;
				}
				if (max != height[i - 1] && min != height[i - 1] || max != height[i + 1] && min != height[i + 1]) {
					++ans;
				}
			}

			System.out.println(ans);
			scan.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
0