답안 #148755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148755 2019-09-01T05:03:06 Z 20190901(#3597, tongnamuu, jf297, upple1) HicCup (FXCUP4_hiccup) C++17
24 / 100
457 ms 20412 KB
#include "hiccup.h"
#include <vector>

using namespace std;


bool Check(string str, int mid)
{
	vector<pair<char, int>> stk;

	int hCnt = 0;
	int cCnt = 0;
	for (int i = 0; i < str.size(); i++)
	{
		if (str[i] == 'H')
		{
			stk.push_back({ 'H', -1 });
			hCnt++;
		}
		else if (str[i] == 'C')
		{
			if (hCnt > cCnt)
				stk.push_back({ 'C', 0 });
			else
				return false;
			cCnt++;
		}
		else
		{
			if (stk.empty() || stk.back().first == 'H')
				continue;
			else
				stk.push_back({ '!', stk.back().second + 1 });
		}

		if (stk.back().second == mid)
		{
			for (int i = 0; i < mid + 2; i++)
			{
				if (stk.empty())
					return false;
				stk.pop_back();
			}
		}
	}

	for (int i = 0; i < stk.size(); i++)
	{
		if (stk[i].first != '!')
			return false;
	}
	return true;
}

int HicCup(string S)
{
	int lo = -1;
	int hi = (int)S.size();


	while (lo + 1 < hi)
	{
		int mid = (lo + hi) >> 1;
		if (Check(S, mid))
		{
			lo = mid;
		}
		else
		{
			hi = mid;
		}
	}

	return lo;
}

Compilation message

hiccup.cpp: In function 'bool Check(std::__cxx11::string, int)':
hiccup.cpp:13:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < str.size(); i++)
                  ~~^~~~~~~~~~~~
hiccup.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < stk.size(); i++)
                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 128 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 18 ms 1348 KB Output is correct
5 Correct 440 ms 20412 KB Output is correct
6 Correct 16 ms 4268 KB Output is correct
7 Correct 15 ms 4352 KB Output is correct
8 Correct 457 ms 20380 KB Output is correct
9 Correct 450 ms 20236 KB Output is correct
10 Correct 16 ms 4352 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 128 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 18 ms 1348 KB Output is correct
5 Correct 440 ms 20412 KB Output is correct
6 Correct 16 ms 4268 KB Output is correct
7 Correct 15 ms 4352 KB Output is correct
8 Correct 457 ms 20380 KB Output is correct
9 Correct 450 ms 20236 KB Output is correct
10 Correct 16 ms 4352 KB Output is correct
11 Correct 96 ms 7976 KB Output is correct
12 Correct 155 ms 11332 KB Output is correct
13 Correct 34 ms 6036 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Incorrect 325 ms 20276 KB Output isn't correct
16 Halted 0 ms 0 KB -