답안 #149891

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149891 2019-09-01T07:21:17 Z =SUM(D1:D9)(#3629, ydk1104, stet_stet, Hyperbolic) HicCup (FXCUP4_hiccup) C++17
컴파일 오류
0 ms 0 KB
#include<vector>
#include<algorithm>
#include "hiccup.h"

int HicCup(std::string S) {
	int N = S.size();
	int stack = 0, laststack = 0;
	int mark = 0;
	std::vector<int> v;
	for(auto i:S){
		if(i == '!') mark++;
	}
	int left=0, right=mark, prev = 'H';
	for(int i=0; i<N; i++){
		if(S[i] == 'H') stack++, 
		if(S[i] == 'C'){
			stack--;
			if(stack < 0) return -1;
			v.push_back(mark);
		}
		if(S[i] == '!') mark--;
		if(S[i] == '!' && prev == 'H') return -1;
		prev = S[i];
	}
	while(left < right){
		int mid = (left+right)/2;
		int prev = v[0];
		for(auto i:v){
			prev = std::min(prev, i) - mid;
		}
		if(prev < 0) right = mid-1;
		left = mid+1;
	}
	int ans = 0;
	for(int mid=left-3; mid <= left+3; mid++){
		int prev = v[0];
		for(auto i:v){
			prev = std::min(prev, i) - mid;
		}
		if(prev < 0) break;
		ans = mid;
	}
	if(stack) return -1;
	return ans;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:16:3: error: expected primary-expression before 'if'
   if(S[i] == 'C'){
   ^~
hiccup.cpp:7:17: warning: unused variable 'laststack' [-Wunused-variable]
  int stack = 0, laststack = 0;
                 ^~~~~~~~~