Submission #38943

# Submission time Handle Problem Language Result Execution time Memory
38943 2018-01-08T08:34:02 Z cheater2k Global Warming (NOI13_gw) C++14
40 / 40
299 ms 15480 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 5;

int n;
vector< pair<int,int> > vec;
int ans, cur;
bool check[N];

void add(int pos) {
	check[pos] = 1;
	if (pos > 1 && pos < n && check[pos - 1] && check[pos + 1]) {
		--cur; return;
	}
	bool flag = false;
	flag |= (pos > 1 && check[pos - 1]);
	flag |= (pos < n && check[pos + 1]);
	if (!flag) ++cur;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int x; cin >> x; 
		vec.push_back(make_pair(x, i));
	}
	sort(vec.begin(), vec.end(), greater< pair<int,int> >());
	
	for (int i = 0; i < vec.size(); ) {
		int height = vec[i].first;
		while(i < vec.size() && vec[i].first == height) {
			add(vec[i].second);
			++i;
		}
		ans = max(ans, cur);
	}

	cout << ans << endl;
}

Compilation message

gw.cpp: In function 'int main()':
gw.cpp:31:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < vec.size(); ) {
                    ^
gw.cpp:33:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(i < vec.size() && vec[i].first == height) {
           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3152 KB Output is correct
2 Correct 0 ms 3152 KB Output is correct
3 Correct 0 ms 3152 KB Output is correct
4 Correct 0 ms 3152 KB Output is correct
5 Correct 0 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 4728 KB Output is correct
2 Correct 13 ms 4728 KB Output is correct
3 Correct 26 ms 4728 KB Output is correct
4 Correct 29 ms 4728 KB Output is correct
5 Correct 19 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 4728 KB Output is correct
2 Correct 9 ms 4728 KB Output is correct
3 Correct 23 ms 4728 KB Output is correct
4 Correct 23 ms 4728 KB Output is correct
5 Correct 26 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 266 ms 15480 KB Output is correct
2 Correct 256 ms 15480 KB Output is correct
3 Correct 299 ms 15480 KB Output is correct
4 Correct 286 ms 15480 KB Output is correct
5 Correct 236 ms 15480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 266 ms 15480 KB Output is correct
2 Correct 286 ms 15480 KB Output is correct
3 Correct 289 ms 15480 KB Output is correct
4 Correct 239 ms 15480 KB Output is correct
5 Correct 223 ms 15480 KB Output is correct