Submission #149445

#TimeUsernameProblemLanguageResultExecution timeMemory
149445잉여로운 고3 (#200)HicCup (FXCUP4_hiccup)C++17
24 / 100
43 ms3456 KiB
#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;

int HicCup(string S) {
	int N = S.size();
	int sum = 0;
	for(int i = 0; i < S.size(); i++) {
		if(S[i] == 'H') sum++;
		else if(S[i] == 'C') sum--;
		if(sum < 0) return -1;
	}
	if(sum != 0) return -1;
	int fc = S.size();
	for(int i = S.size() - 1; i >= 0; i--) if(S[i] == 'C') fc = i;
	if(fc == S.size()) return -1;
	for(int i = 0; i < fc; i++) if(S[i] == '!') return -1;

	int s = 0, e = S.size() - 1;
	while(s < e) {
		int m = (s + e + 1) / 2;
		int cnt = 0;
		bool b = true;
		for(int i = S.size() - 1; i >= 0; i--) {
			if(S[i] == '!') cnt++;
			else if(S[i] == 'C') cnt -= m;
			if(cnt < 0) b = false;
		}
		if(b) s = m;
		else e = m - 1;
	}
	return s;
}

Compilation message (stderr)

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:8:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < S.size(); i++) {
                 ~~^~~~~~~~~~
hiccup.cpp:16:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(fc == S.size()) return -1;
     ~~~^~~~~~~~~~~
hiccup.cpp:6:6: warning: unused variable 'N' [-Wunused-variable]
  int N = S.size();
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...