记录编号 175669 评测结果 AAAAAAAAAAAAAAA
题目名称 [USACO Open12] 淹没岛屿 最终得分 100
用户昵称 Gravatar啊吧啦吧啦吧 是否通过 通过
代码语言 C++ 运行时间 0.980 s
提交时间 2015-08-06 17:32:27 内存使用 0.74 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <ctime>
//#define self

using namespace std;
typedef set<int> si;
typedef vector<int> vi;
typedef multimap<int, int> mii;

const int MAXN(100001);
int n, h[MAXN], ans = 0, nans = 1, last;
mii ah;
bool yan[MAXN] = {false};

inline int in(){
	int x = 0;
	char c;
	while(! isdigit(c = getchar()));
	while(isdigit(c)){
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x;
}

main()
{
#ifndef self
	FILE *fout;
	freopen("islands.in", "r", stdin);
	fout = fopen("islands.out", "w");
#endif
	n = in();
	for (int i = 1; i <= n; ++i){
		h[i] = in();
		ah.insert(make_pair(h[i], i));
	}
//	for (mii::iterator it = ah.begin(); it != ah.end(); ++it)
//		cout << it->first << ' ' << it->second << endl;
	last = 0;
	for (mii::iterator it = ah.begin(); it != ah.end(); ++it){
		if (it->first != last){
			last = it->first;
			ans = max(ans, nans);
		}
		bool have = 0;
		yan[it->second] = true;
		if (it->second == 1){
			if (yan[2])
				nans--;
			have = 1;
		}
		if (it->second == n){
			if (yan[n - 1])
				nans--;
			have = 1;
		}
		if((! have) && yan[it->second - 1] && yan[it->second + 1])
			nans--;
		if(! (have || yan[it->second - 1] || yan[it->second + 1]))
			nans++;
	}
	
#ifdef self
	cout << ans;
	for(;;);
#else
	fprintf(fout, "%d", ans);
	fclose(stdin);
	fclose(fout);
#endif
}