답안 #150173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150173 2019-09-01T07:50:41 Z 준표야 함수컵은 캐리해줄거지?(#3588, Acka, spectaclehong, heiler) HicCup (FXCUP4_hiccup) C++17
100 / 100
215 ms 11136 KB
#include "hiccup.h"

#include <cstdio>
#include <algorithm>

using namespace std;

int st[1000006] = {-1};
int top;
bool chk(string &S, int k) {
	top = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'H') {
			st[++top] = -1;
		}
		else if (S[i] == 'C') {
			st[++top] = -2;
		}
		else if (S[i] == '!') {
			if (st[top] < 0) st[++top] = 1;
			else st[top]++;
			if (st[top - 1] == -1) top--;
		}
		if (k) while (top > 2 && st[top - 2] == -1 && st[top - 1] == -2 && st[top] >= k) {
			st[top - 2] = st[top] - k;
			top -= 2;
			while (st[top - 1] >= 0) {
				st[top - 1] += st[top];
				top--;
			}
			while (st[top] == 0) top--;
		}
		else {
			while (st[top] >= 0) top--;
			while (top > 1 && st[top - 1] == -1 && st[top] == -2) {
				top -= 2;
				while (st[top] >= 0) top--;
			}
		}
	}
	return !top;
}


int HicCup(std::string S) {
	int st[1000006] = {0};
	int top = 0;
	if (S[0] != 'H') return -1;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'H') {
			st[top]++;
			st[++top] = 0;
		}
		else if (S[i] == 'C') {
			if (st[top] == 0 && S[i - 1] != 'H') return -1;
			top--;
		}
		if (S[i] == '!' && S[i -1] == 'H') return -1;
		if (top < 0) return -1;
	}
	if (top) return -1;
	int l = 0, r = S.size();
	while (l + 1 < r) {
		int mid = l + r >> 1;
		if (!chk(S, mid)) r = mid;
		else l = mid;
	}
	return l;
}

// int main() {
// 	int ret = HicCup("HHC!!C!");
// 	printf("%d\n", ret);
// }

Compilation message

hiccup.cpp: In function 'bool chk(std::__cxx11::string&, int)':
hiccup.cpp:12:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < S.size(); i++) {
                  ~~^~~~~~~~~~
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:49:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < S.size(); i++) {
                  ~~^~~~~~~~~~
hiccup.cpp:64:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1;
             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4352 KB Output is correct
2 Correct 7 ms 4224 KB Output is correct
3 Correct 7 ms 4352 KB Output is correct
4 Correct 13 ms 4480 KB Output is correct
5 Correct 199 ms 11128 KB Output is correct
6 Correct 15 ms 7296 KB Output is correct
7 Correct 15 ms 7168 KB Output is correct
8 Correct 195 ms 11136 KB Output is correct
9 Correct 206 ms 11128 KB Output is correct
10 Correct 16 ms 7296 KB Output is correct
11 Correct 7 ms 4352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4352 KB Output is correct
2 Correct 7 ms 4224 KB Output is correct
3 Correct 7 ms 4352 KB Output is correct
4 Correct 13 ms 4480 KB Output is correct
5 Correct 199 ms 11128 KB Output is correct
6 Correct 15 ms 7296 KB Output is correct
7 Correct 15 ms 7168 KB Output is correct
8 Correct 195 ms 11136 KB Output is correct
9 Correct 206 ms 11128 KB Output is correct
10 Correct 16 ms 7296 KB Output is correct
11 Correct 17 ms 7296 KB Output is correct
12 Correct 15 ms 7168 KB Output is correct
13 Correct 15 ms 7168 KB Output is correct
14 Correct 7 ms 4224 KB Output is correct
15 Correct 16 ms 7168 KB Output is correct
16 Correct 7 ms 4352 KB Output is correct
17 Correct 8 ms 4352 KB Output is correct
18 Correct 9 ms 4480 KB Output is correct
19 Correct 106 ms 7296 KB Output is correct
20 Correct 114 ms 7168 KB Output is correct
21 Correct 107 ms 7296 KB Output is correct
22 Correct 101 ms 7040 KB Output is correct
23 Correct 105 ms 7288 KB Output is correct
24 Correct 114 ms 7424 KB Output is correct
25 Correct 215 ms 10752 KB Output is correct
26 Correct 135 ms 8448 KB Output is correct
27 Correct 107 ms 7296 KB Output is correct
28 Correct 99 ms 7168 KB Output is correct
29 Correct 106 ms 7288 KB Output is correct
30 Correct 8 ms 4352 KB Output is correct
31 Correct 8 ms 4352 KB Output is correct
32 Correct 14 ms 4480 KB Output is correct
33 Correct 7 ms 4352 KB Output is correct