結果

問題 No.284 門松と魔法(2)
ユーザー togari_takamoto
提出日時 2015-10-08 08:16:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 806 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 62,724 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-20 02:01:45
合計ジャッジ時間 1,698 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

#define TEN(x) ((ll)1e##x)

enum State{High, Low};

ll calc(const vector<ll> & a ,State s) {
	ll count = 0;
	ll prepre_size = (s==Low) ? 0 : TEN(6)+1;
	ll prev_size = (s==High) ? 0 : TEN(6)+1;
	for (auto& x : a) {
		if (prepre_size == x) {
			count++; continue;
		}

		if (s == High) {
			if (prev_size < x) {
				s = Low;
			} else {
				count++;
			}
		} else {
			if (prev_size > x) {
				s = High;
			} else {
				count++;
			}
		}
		prepre_size = prev_size;
		prev_size = x;
	}
	return a.size() - count;
}

int main(){
	ll n; cin >> n;
	vector<ll> a(n);
	for (auto& i : a) cin >> i;
	ll result = max(calc(a, Low), calc(a, High));
	if (result < 3) result = 0;
	cout << result << endl;
	return 0;
}
0