結果

問題 No.116 門松列(1)
ユーザー spaciaspacia
提出日時 2016-01-04 08:57:37
言語 Java19
(openjdk 21)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 799 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 74,692 KB
実行使用メモリ 49,468 KB
最終ジャッジ日時 2023-09-07 06:54:15
合計ジャッジ時間 4,379 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,280 KB
testcase_01 AC 44 ms
49,124 KB
testcase_02 AC 45 ms
49,468 KB
testcase_03 AC 44 ms
47,236 KB
testcase_04 AC 44 ms
49,164 KB
testcase_05 AC 45 ms
49,176 KB
testcase_06 AC 45 ms
49,132 KB
testcase_07 AC 45 ms
49,412 KB
testcase_08 AC 44 ms
49,272 KB
testcase_09 AC 45 ms
49,236 KB
testcase_10 AC 45 ms
49,172 KB
testcase_11 AC 45 ms
47,200 KB
testcase_12 AC 46 ms
49,232 KB
testcase_13 AC 45 ms
47,352 KB
testcase_14 AC 46 ms
49,124 KB
testcase_15 AC 45 ms
49,196 KB
testcase_16 AC 46 ms
48,996 KB
testcase_17 AC 47 ms
49,244 KB
testcase_18 AC 46 ms
49,248 KB
testcase_19 AC 45 ms
49,104 KB
testcase_20 AC 46 ms
49,072 KB
testcase_21 AC 48 ms
49,180 KB
testcase_22 AC 47 ms
49,176 KB
testcase_23 AC 47 ms
49,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.math.*;

class Main {
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static boolean isPd (int a , int b , int c) {
		if (a == b || a == c || b == c) return false;
		return (c < a && a < b) || (b < a && a < c) || (a < c && c < b) || (b < c && c < a);
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] line = br.readLine().split(" ");
		
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(line[i]);
		}
		int ans = 0;
		for (int i = 2; i < n; i++) {
			ans = isPd(a[i - 2] , a[i - 1] , a[i]) ? ans + 1 : ans;
		}
		
		out(ans);
		
	}
}
0