結果

問題 No.116 門松列(1)
ユーザー YamaKasaYamaKasa
提出日時 2018-04-24 22:41:45
言語 Java19
(openjdk 21)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 520 bytes
コンパイル時間 2,828 ms
コンパイル使用メモリ 71,100 KB
実行使用メモリ 56,060 KB
最終ジャッジ日時 2023-09-07 07:22:57
合計ジャッジ時間 7,317 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
55,688 KB
testcase_01 AC 125 ms
55,776 KB
testcase_02 AC 125 ms
55,680 KB
testcase_03 AC 127 ms
56,060 KB
testcase_04 AC 125 ms
55,488 KB
testcase_05 AC 129 ms
56,036 KB
testcase_06 AC 129 ms
56,032 KB
testcase_07 AC 126 ms
55,492 KB
testcase_08 AC 126 ms
55,320 KB
testcase_09 AC 128 ms
55,768 KB
testcase_10 AC 132 ms
55,828 KB
testcase_11 AC 131 ms
55,680 KB
testcase_12 AC 137 ms
55,796 KB
testcase_13 AC 127 ms
55,664 KB
testcase_14 AC 134 ms
55,712 KB
testcase_15 AC 125 ms
55,904 KB
testcase_16 AC 132 ms
55,660 KB
testcase_17 AC 131 ms
55,912 KB
testcase_18 AC 134 ms
55,832 KB
testcase_19 AC 126 ms
55,964 KB
testcase_20 AC 134 ms
55,792 KB
testcase_21 AC 135 ms
55,752 KB
testcase_22 AC 129 ms
55,784 KB
testcase_23 AC 139 ms
55,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int []A = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		scan.close();
		int ans = 0;
		for(int i = 0; i < N - 2; i++) {
			int a1 = A[i];
			int a2 = A[i + 1];
			int a3 = A[i + 2];
			if(a1 < a2 && a2 > a3 && a1 != a3) {
				ans ++;
			}else if(a1 > a2 && a2 < a3 && a1 != a3) {
				ans ++;
			}
		}
		System.out.println(ans);

	}
}
0