結果

問題 No.116 門松列(1)
ユーザー KKT89
提出日時 2020-01-06 05:58:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 498 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 74,760 KB
最終ジャッジ日時 2025-01-08 16:26:18
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
 
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int ans=0;
	for(int i=0;i<n-2;i++){
		if(a[i]>a[i+1]&&a[i]<a[i+2]){
			ans++;
		}
		if(a[i]>a[i+2]&&a[i]<a[i+1]){
			ans++;
		}
		if(a[i+2]>a[i+1]&&a[i+2]<a[i]){
			ans++;
		}
		if(a[i+2]>a[i]&&a[i+2]<a[i+1]){
			ans++;
		}
	}
	cout << ans << endl;
}
0