Submission #150955

# Submission time Handle Problem Language Result Execution time Memory
150955 2019-09-01T13:01:41 Z JustInCase HicCup (FXCUP4_hiccup) C++17
0 / 100
2 ms 256 KB
#include <bits/stdc++.h>

#ifdef LOCAL
	#include "grader.cpp"
#else
	#include "hiccup.h"
#endif

#define hic_cup HicCup

bool check_is_x_string(const std::string &s, int32_t x) {
	std::stack< int32_t > st;
	
	bool isLastReady = false;
	for(int32_t i = 0; i < s.size(); i++) {
		if(s[i] == 'C') {
			st.push(x);
			isLastReady = false;
		}
		else if(s[i] == '!') {
			if(!st.empty()) {
				int32_t aux = st.top();
				st.pop();

				aux--;
				if(aux != 0) {
					st.push(aux);
				}
			}
		}
	}

	if(st.empty()) {
		return true;
	}
	else {
		return false;
	}
}

int32_t hic_cup(std::string s) {
	int32_t low = 1, high = s.size();
	while(low <= high) {
		int32_t mid = (low + high) / 2;

		if(check_is_x_string(s, mid)) {
			low = mid + 1;
		}
		else {
			high = mid - 1;
		}
	}

	return low - 1;
}

Compilation message

hiccup.cpp: In function 'bool check_is_x_string(const string&, int32_t)':
hiccup.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int32_t i = 0; i < s.size(); i++) {
                     ~~^~~~~~~~~~
hiccup.cpp:14:7: warning: variable 'isLastReady' set but not used [-Wunused-but-set-variable]
  bool isLastReady = false;
       ^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -