제출 #150282

#제출 시각아이디문제언어결과실행 시간메모리
150282GucciBelt (#200)HicCup (FXCUP4_hiccup)C++17
24 / 100
178 ms6420 KiB
#include "hiccup.h" #include <bits/stdc++.h> using namespace std; const int N = 1e6+5; int n; bool checkFunction(string str, int mid) { stack<int> stk; for(int i = 0; i < n; ++i) { if(str[i] == 'C') stk.emplace(0); if(str[i] == '!') { if(stk.empty()) continue; int v = stk.top(); stk.pop(); if(++v == mid) continue; stk.emplace(v); } } return stk.empty(); } int HicCup(string S) { n = S.size(); int cnt = 0; bool state = false; for(int i = 0; i < n; ++i) { if(S[i] == 'H') cnt++, state = false; if(S[i] == 'C') if(!~--cnt) return -1; else state = true; if(S[i] == '!') if(!state) return -1; } if(cnt) return -1; int l = 0, r = S.size(); while(l < r) { int mid = (l + r + 1) >> 1; if(checkFunction(S, mid)) l = mid; else r = mid-1; } return l; }

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

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:30:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   if(S[i] == 'C') if(!~--cnt) return -1; else state = true;
     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...