제출 #1117551

#제출 시각아이디문제언어결과실행 시간메모리
1117551secretwood01Global Warming (NOI13_gw)C++17
40 / 40
383 ms14940 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; }

컴파일 시 표준 에러 (stderr) 메시지

gw.cpp: In function 'bool funt(int, std::vector<Element>&)':
gw.cpp:23:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Element>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     while (islands < mid && index < T.size()) {
      |                             ~~~~~~^~~~~~~~~~
gw.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Element>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         while (index < T.size() && T[index].val == currVal) {
      |                ~~~~~~^~~~~~~~~~
gw.cpp:29:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             bool right = curr.ind == v.size() - 1 || !v[curr.ind + 1];
      |                          ~~~~~~~~~^~~~~~~~~~~~~~~
gw.cpp:32:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             bool negRight = curr.ind != v.size() - 1 && v[curr.ind + 1];
      |                             ~~~~~~~~~^~~~~~~~~~~~~~~
#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...