Submission #150665

#TimeUsernameProblemLanguageResultExecution timeMemory
150665Solo Leveling (#200)HicCup (FXCUP4_hiccup)C++17
0 / 100
6 ms512 KiB
#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;

struct item{
	int h , c , x;
};

int HicCup(std::string S) {
	int N = S.size();
	int l = 0 , r = N-2;
	int ansj = -1;
	while(l<=r){
		int mid = (l+r)/2;
		bool can = true;
		stack<item >s;
		bool jateve = false;
		for(int i = 0 ; i < S.size() ; i ++){
			if(S[i] == 'H'){
				s.push({0 , 1 , mid});
			}
			else if(S[i] == 'C'){
				jateve = true;
				if(s.empty()){
					can = false;
					break;
				}
				if(s.top().c == 0){
					can = false;
					break;
				}
				s.top().c--;
			}
			else{
				if(s.empty() && !jateve){
					can = false;
					break;
				}
				if(!s.empty()){
				if(s.top().c == 0)
				while(!s.empty() && s.top().c == 0){
					if(s.top().x == 0){
						s.pop();
					}
					else{
						s.top().x--;
						if(s.top().x == 0){
							s.pop();
						}
						break;
					}
				}
				else{
					if(!jateve){
						can = false;
						break;
					}
				}
			}

			}
		}
		while(s.size() && s.top().c == 0 && s.top().x == 0) s.pop();
		if(s.size()) can = false;
		if(can){
			ansj = mid;
			l = mid +1;
		}
		else r = mid - 1;
	}
	return ansj;
}

Compilation message (stderr)

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:18:21: 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...