Submission #149594

# Submission time Handle Problem Language Result Execution time Memory
149594 2019-09-01T06:48:01 Z etyu(#3586, kimjihoon) HicCup (FXCUP4_hiccup) C++17
100 / 100
86 ms 4352 KB
#include "hiccup.h"
#include <vector>

std::string s;
int N;
std::vector<int> st;

bool ps(int l)
{
	st.clear();
	for (int i = 0; i < N; i++) {
		if (s[i] == 'H') st.push_back(-1);
		else if (s[i] == 'C') {
			if (st.back() != -1) return false;
			st.back() = 0;
			if (l == 0) st.pop_back();
		}
		else {
			if (st.empty() || st.back() == -1) continue;
			st.back()++;
			if (st.back() >= l) st.pop_back();
		}
	}
	return st.empty();
}

int bs(int s, int e)
{
	int md = (s + e + 1) / 2;
	if (s >= e) return md;
	if (ps(md)) return bs(md, e);
	else return bs(s, md - 1);
}

int HicCup(std::string S) {
	N = S.size();
	s = S;
	int c = 0;
	bool f = false;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'H') {
			f = false; c++;
		}
		else if (S[i] == 'C') {
			f = true; c--;
		}
		else if (!f) return -1;
		if (c < 0) return -1;
	}
	if (c != 0) return -1;
	return bs(0, N);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 20 ms 4272 KB Output is correct
6 Correct 13 ms 4352 KB Output is correct
7 Correct 15 ms 4224 KB Output is correct
8 Correct 20 ms 4224 KB Output is correct
9 Correct 19 ms 4352 KB Output is correct
10 Correct 13 ms 4352 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 20 ms 4272 KB Output is correct
6 Correct 13 ms 4352 KB Output is correct
7 Correct 15 ms 4224 KB Output is correct
8 Correct 20 ms 4224 KB Output is correct
9 Correct 19 ms 4352 KB Output is correct
10 Correct 13 ms 4352 KB Output is correct
11 Correct 15 ms 4352 KB Output is correct
12 Correct 14 ms 4352 KB Output is correct
13 Correct 13 ms 4224 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 14 ms 4352 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 32 ms 4352 KB Output is correct
20 Correct 19 ms 4224 KB Output is correct
21 Correct 58 ms 4352 KB Output is correct
22 Correct 53 ms 4096 KB Output is correct
23 Correct 86 ms 4224 KB Output is correct
24 Correct 17 ms 4352 KB Output is correct
25 Correct 21 ms 4352 KB Output is correct
26 Correct 19 ms 4272 KB Output is correct
27 Correct 58 ms 4352 KB Output is correct
28 Correct 77 ms 4352 KB Output is correct
29 Correct 79 ms 4224 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 9 ms 640 KB Output is correct
33 Correct 5 ms 384 KB Output is correct