結果
| 問題 |
No.116 門松列(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-01-22 22:58:19 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 5,000 ms |
| コード長 | 984 bytes |
| コンパイル時間 | 3,691 ms |
| コンパイル使用メモリ | 78,192 KB |
| 実行使用メモリ | 37,376 KB |
| 最終ジャッジ日時 | 2024-06-25 01:36:17 |
| 合計ジャッジ時間 | 5,645 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
package me.yukicoder.lv1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class No0116 {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
int N = Integer.parseInt(br.readLine());
String[] str = br.readLine().split(" ");
int[] matsu = new int[N];
int cnt = 0;
for (int i = 0; i < N; i++) {
matsu[i] = Integer.parseInt(str[i]);
}
for (int i = 0; i < N - 2; i++) {
int[] tmp = { matsu[i], matsu[i + 1], matsu[i + 2] };
// 門松列?
cnt = isKadomatsu(tmp) ? cnt + 1 : cnt;
}
System.out.println(cnt);
} catch (IOException e) {
e.printStackTrace();
}
}
static boolean isKadomatsu(int[] matsu) {
int[] tmp = { matsu[0], matsu[1], matsu[2] };
Arrays.sort(tmp);
return (tmp[1] != matsu[1]) &&
(matsu[0] != matsu[1] && matsu[1] != matsu[2] && matsu[0] != matsu[2]);
}
}