Submission #704078

# Submission time Handle Problem Language Result Execution time Memory
704078 2023-03-01T14:04:33 Z Potato3218 Global Warming (NOI13_gw) C++17
0 / 40
98 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define beegspeed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define pvi pair<int,vector<int>>
#define f first
#define s second

vector<int> H;
unordered_map<int,vector<int>> um;
bool submerged[1000007];
vector<pvi> mp;


inline int readInt() {
	beegspeed
    int x;
	cin>>x;
	return x;
}

signed main(){
	beegspeed
	um.reserve(6000000);
	um.max_load_factor(0.25);
	int n = readInt();
	for(int i = 0; i < n; i++){
		int h = readInt();
		H.push_back(h);
		um[h].push_back(i);
	}
	for(auto& itr: um){
		mp.push_back(itr);
	}
	sort(mp.begin(), mp.end(), greater<pvi>());
	int ans = 0, curr = 0;
	for(auto itr: mp){
		for(auto island:itr.second){
			island[submerged] = true;
			//check if neighbouring sections are unsubmerged yet
			if(island == 0){
				int m = 1;
				if(!m[submerged]){
					++curr;
				}
			}
			else if(island == n-1){
				int m = n - 2;
				if(!m[submerged]) ++curr;
			}
			else{
				int p = (!submerged[island + 1]) + (!submerged[island- 1]);
				//if both aren't submerged evaluates to 2, if one of them is submerged evaluates to 1, else it's just 0
				--p;
				curr += p;
			}
		}
		ans = max(ans, curr);
	}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 50956 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 53892 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 62 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 75 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 98 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -