답안 #148653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148653 2019-09-01T04:52:31 Z 준표야 함수컵은 캐리해줄거지?(#3588, Acka, spectaclehong, heiler) HicCup (FXCUP4_hiccup) C++17
컴파일 오류
0 ms 0 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 (top > 1 && st[top - 1] == -1 && st[top] == -2) {
			top -= 2;
		}
	}
	return !top;
}

int HicCup(std::string S) {
	if (S[0] != 'H') return -1;
	int l = -1, 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("!!HC!!");
	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:45:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1;
             ~~^~~
/tmp/ccN6qmv3.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc0vYdk6.o:hiccup.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status