Submission #412853

# Submission time Handle Problem Language Result Execution time Memory
412853 2021-05-27T17:12:16 Z aryan12 Global Warming (NOI13_gw) C++17
19 / 40
799 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void Solve() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	vector<bool> isTaken(n + 3);
	vector<vector<int> > positions(n + 1);
	map<int, int> cc;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		cc[a[i]]++;
		isTaken[i] = false;
	}
	isTaken[0] = true;
	isTaken[n + 1] = true;
	int cnt = 1;
	for(auto i: cc) {
		cc[i.first] = cnt++;
	}
	for(int i = 1; i <= n; i++) {
		a[i] = cc[a[i]];
		positions[a[i]].push_back(i);
	}
	int ans = 0, curr = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < positions[i].size(); j++) {
			int curPosition = positions[i][j];
			isTaken[curPosition] = true;
			if(!isTaken[curPosition - 1] && !isTaken[curPosition + 1]) {
				curr++;
			}
			else if(isTaken[curPosition - 1] && isTaken[curPosition + 1]) {
				curr--;
			}
		}
		ans = max(ans, curr);
	}
	cout << ans + 1 << "\n";
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		Solve();
	}
	return 0;
}

Compilation message

gw.cpp: In function 'void Solve()':
gw.cpp:31:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int j = 0; j < positions[i].size(); j++) {
      |                  ~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 4940 KB Output is correct
2 Correct 17 ms 4804 KB Output is correct
3 Correct 18 ms 4940 KB Output is correct
4 Correct 17 ms 4864 KB Output is correct
5 Correct 21 ms 4932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 13564 KB Output is correct
2 Correct 68 ms 13380 KB Output is correct
3 Correct 119 ms 13624 KB Output is correct
4 Correct 110 ms 13596 KB Output is correct
5 Correct 109 ms 13668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 455 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 799 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -