Submission #150229

#TimeUsernameProblemLanguageResultExecution timeMemory
150229GucciBelt (#200)HicCup (FXCUP4_hiccup)C++17
24 / 100
233 ms5448 KiB
#include "hiccup.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6+5;

int n;

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;
		queue<int> Q;
		bool chk = false;
		for(int i = 0; i < S.size(); i++) {
			if(S[i] == 'C') {
				chk = true;
				Q.emplace(0);
			} else if(S[i] == '!') {
				if(Q.empty() && !chk) return -1;
				else if(!Q.empty()) {
					int now = Q.front(); Q.pop();
					if(now + 1 < mid) Q.emplace(now + 1);
				}
			}
		}
		if(Q.empty()) l = mid;
		else r = mid - 1;
	}	
	return l;
}

Compilation message (stderr)

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:16:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   if(S[i] == 'C') if(!~--cnt) return -1; else state = true;
     ^
hiccup.cpp:25:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < S.size(); i++) {
                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...