結果
問題 |
No.116 門松列(1)
|
ユーザー |
![]() |
提出日時 | 2017-02-03 00:05:05 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 144 ms / 5,000 ms |
コード長 | 674 bytes |
コンパイル時間 | 2,282 ms |
コンパイル使用メモリ | 78,072 KB |
実行使用メモリ | 41,368 KB |
最終ジャッジ日時 | 2024-06-25 01:26:20 |
合計ジャッジ時間 | 6,296 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import java.util.Scanner; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a = new int[n]; for(int i=0; i<n; i++) { a[i] = in.nextInt(); } int count = 0; for(int i=0; i<n-2; i++) { if((a[i+1] < a[i] && a[i] < a[i+2]) || (a[i+1] < a[i+2] && a[i+2] < a[i])) count++; if((a[i+2] < a[i] && a[i] < a[i+1]) || (a[i] < a[i+2] && a[i+2] < a[i+1])) count++; } System.out.println(count); in.close(); } }