Submission #150971

#TimeUsernameProblemLanguageResultExecution timeMemory
150971JustInCaseHicCup (FXCUP4_hiccup)C++17
0 / 100
122 ms3936 KiB
#include <bits/stdc++.h> #ifdef LOCAL #include "grader.cpp" #else #include "hiccup.h" #endif #define hic_cup HicCup bool check_is_valid_input(const std::string &s) { char last; int32_t cntH = 0, cntC = 0; for(int32_t i = 0; i < s.size(); i++) { if(s[i] == 'H') { cntH++; last = 'H'; } else if(s[i] == 'C') { cntC++; last = 'C'; } else { if(last == 'H' || cntH == 0) { return false; } } if(cntC > cntH) { return false; } } return true; } bool check_is_x_string(const std::string &s, int32_t x) { std::stack< int32_t > stH; std::stack< std::pair< int32_t, int32_t > > st; for(int32_t i = 0; i < s.size(); i++) { if(s[i] == 'H') { stH.push(i); } else if(s[i] == 'C') { if(!st.empty() && st.top().first > stH.top()) { return false; } st.push({stH.top(), x}); stH.pop(); } else { if(!st.empty()) { auto aux = st.top(); st.pop(); aux.second--; if(aux.second != 0) { st.push(aux); } } } } if(st.empty()) { return true; } else { return false; } } int32_t hic_cup(std::string s) { if(!check_is_valid_input(s)) { return -1; } int32_t low = 1, high = s.size(); while(low <= high) { int32_t mid = (low + high) / 2; if(check_is_x_string(s, mid)) { low = mid + 1; } else { high = mid - 1; } } return low - 1; }

Compilation message (stderr)

hiccup.cpp: In function 'bool check_is_valid_input(const string&)':
hiccup.cpp:16:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int32_t i = 0; i < s.size(); i++) {
                     ~~^~~~~~~~~~
hiccup.cpp: In function 'bool check_is_x_string(const string&, int32_t)':
hiccup.cpp:43:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int32_t i = 0; i < s.size(); i++) {
                     ~~^~~~~~~~~~
hiccup.cpp: In function 'bool check_is_valid_input(const string&)':
hiccup.cpp:26:12: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if(last == 'H' || cntH == 0) {
       ~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...