Submission #618043

#TimeUsernameProblemLanguageResultExecution timeMemory
618043czhang2718HicCup (FXCUP4_hiccup)C++17
24 / 100
25 ms6284 KiB
// #include "hiccup.h"
using namespace std;
#include "bits/stdc++.h"

bool check(string s){
	int ps=0;
	for(char c:s){
		if(c=='H') ps++;
		else ps--;
		if(ps<0) return 0;
	}
	return ps==0;
}

int HicCup(std::string S) {
	string t="";
	for(char c:S) if(c!='!') t+=c;
	if(!check(t)) return -1;
	t="";
	for(char c:S) if(c!='H') t+=c;
	int exc=0, c=0;
	for(int i=0; i<S.size(); i++){
		if(S[i]=='!' && (!i || S[i-1]=='H')) return -1;
	}
	int ans=1e9;
	for(int i=t.size()-1; i>=0; i--){
		(t[i]=='!'?exc:c)++;
		if(t[i]=='C') ans=min(ans, exc/c);
	}
	assert(ans!=1e9);
	return ans;
}
 
// int main(){
// 	string s;
// 	cin >> s;
// 	cout << HicCup(s);
// }

Compilation message (stderr)

hiccup.cpp: In function 'int HicCup(std::string)':
hiccup.cpp:22:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(int i=0; i<S.size(); i++){
      |               ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...