답안 #149320

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149320 2019-09-01T06:14:48 Z 20190901(#3597, tongnamuu, jf297, upple1) HicCup (FXCUP4_hiccup) C++17
100 / 100
441 ms 20416 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;
	bool isMake = false;
	for (int i = 0; i < str.size(); i++)
	{
		if (stk.empty() && str[i] != '!')
			isMake = false;

		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())
			{
				if (isMake)
					continue;
				else
					return false;
			}
			if (stk.back().first == 'H')
			{
				if (isMake)
					continue;
				else
					return false;
			}

			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;

				if (stk.back().first == 'C')
					cCnt--;
				else if (stk.back().first == 'H')
					hCnt--;
				stk.pop_back();
			}
			isMake = true;
		}
	}

	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:14:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < str.size(); i++)
                  ~~^~~~~~~~~~~~
hiccup.cpp:69:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < stk.size(); i++)
                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 18 ms 1396 KB Output is correct
5 Correct 436 ms 20396 KB Output is correct
6 Correct 16 ms 4348 KB Output is correct
7 Correct 16 ms 4352 KB Output is correct
8 Correct 426 ms 20408 KB Output is correct
9 Correct 426 ms 20416 KB Output is correct
10 Correct 17 ms 4352 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 18 ms 1396 KB Output is correct
5 Correct 436 ms 20396 KB Output is correct
6 Correct 16 ms 4348 KB Output is correct
7 Correct 16 ms 4352 KB Output is correct
8 Correct 426 ms 20408 KB Output is correct
9 Correct 426 ms 20416 KB Output is correct
10 Correct 17 ms 4352 KB Output is correct
11 Correct 132 ms 18248 KB Output is correct
12 Correct 198 ms 17884 KB Output is correct
13 Correct 35 ms 6012 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 56 ms 13500 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 11 ms 928 KB Output is correct
19 Correct 329 ms 20404 KB Output is correct
20 Correct 340 ms 20408 KB Output is correct
21 Correct 270 ms 20232 KB Output is correct
22 Correct 373 ms 19788 KB Output is correct
23 Correct 441 ms 20072 KB Output is correct
24 Correct 348 ms 20412 KB Output is correct
25 Correct 441 ms 20404 KB Output is correct
26 Correct 399 ms 20380 KB Output is correct
27 Correct 299 ms 20404 KB Output is correct
28 Correct 330 ms 20028 KB Output is correct
29 Correct 306 ms 18432 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 23 ms 2204 KB Output is correct
33 Correct 6 ms 384 KB Output is correct