Submission #1130076

#TimeUsernameProblemLanguageResultExecution timeMemory
1130076Roumak77Global Warming (NOI13_gw)C++17
40 / 40
468 ms12712 KiB
#include <iostream> #include <vector> #include <algorithm> #include <fstream> using namespace std; class Element { private: int nothing; public: int val; int ind; Element(int val, int ind) : val(val), ind(ind) {} bool operator<(const Element& o) const { return val > o.val; // For descending order } }; bool funt(int mid, std::vector<Element>& T) { int islands = 0; int index = 0; std::vector<bool> v(T.size(), false); while (islands < mid && index < T.size()) { int currVal = T[index].val; while (index < T.size() && T[index].val == currVal) { Element curr = T[index]; v[curr.ind] = true; bool left = curr.ind == 0 || !v[curr.ind - 1]; bool right = curr.ind == v.size() - 1 || !v[curr.ind + 1]; if (left && right) islands++; bool negLeft = curr.ind != 0 && v[curr.ind - 1]; bool negRight = curr.ind != v.size() - 1 && v[curr.ind + 1]; if (negLeft && negRight) islands--; index++; } } return islands >= mid; } int bs(std::vector<Element>& T) { int lo = 1; int hi = T.size(); while (lo < hi) { int mid = lo + (hi - lo + 1) / 2; if (funt(mid, T)) { lo = mid; } else { hi = mid - 1; } } return lo; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int N; std::cin >> N; std::vector<Element> Arr; for (int i = 0; i < N; i++) { int value; std::cin >> value; Arr.emplace_back(value, i); } std::sort(Arr.begin(), Arr.end()); std::cout << bs(Arr) << std::endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...