Submission #150429

# Submission time Handle Problem Language Result Execution time Memory
150429 2019-09-01T08:23:25 Z Little Piplup(#3742, gratus907, DHdroid, coffeetea99) HicCup (FXCUP4_hiccup) C++17
24 / 100
256 ms 6320 KB
#include "hiccup.h"
#include<bits/stdc++.h>
//using namespace std;
std::string str;
std::string ss;
bool check(int x)
{
	int excount = 0;
	ss.clear();
	if (x+2 > str.size())
		return false;
	int ssize = 0;
	int ccount = 0;
	for (auto it:str)
	{
		if (it=='!')
			excount++;
		else 
		{
			ss.push_back(it);
			if (it=='C')
				ccount++;
			ssize++;
		}
		
		if (ssize < 2)
		{
			//std::cout << ss << std::endl;
			continue;
		}
		bool ok = true;
		ok &= ss[ssize-2] == 'C';
		ok &= ss[ssize-1] == 'H';
		ok &= (excount >= x);
		if (ok)
		{
			ss.pop_back();
			ss.pop_back();
			ssize-=2;
			ccount--;
			excount -= x;
		}
		//std::cout << ss << std::endl;
	}
	for (auto it:ss)
	{
		if (it!='!')
			return false;
	}
	return true;
}
bool zerocheck()
{
	std::string tmpstr = "";
	for (auto it:str)
	{
		tmpstr.push_back(it);
		int sz = tmpstr.size();
		if (sz>=2)
		{
			while (tmpstr[sz-1] == 'H' && tmpstr[sz-2] == 'C')
			{
				tmpstr.pop_back();
				tmpstr.pop_back();
				sz-=2;
				while(tmpstr.back()=='!')
				{
					tmpstr.pop_back();
					sz--;
				}
			}
		}
		else continue;
	}
	//std::cout << "zerocheck : " << tmpstr << std::endl;
	return tmpstr.empty();
}
int HicCup(std::string S) {
	int N = S.size();
	if ( S[0] != 'H' ) return -1;
	str = S;
	std::reverse(str.begin(), str.end());
	//std::cout << str << std::endl;
	int lo = 0, hi = 1000000;
	if (!zerocheck())
		return -1;
	while(lo + 1 < hi)
	{
		int mid = lo+hi;
		mid /= 2;
		//printf("Checking %d\n",mid);
		if (check(mid))
		{
			//printf("OK %d\n",mid);
			lo = mid;
		}
		else 
		{
			//printf("NO %d\n",mid);
			hi = mid;
		}
	}
	return lo;
}

Compilation message

hiccup.cpp: In function 'bool check(int)':
hiccup.cpp:10:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (x+2 > str.size())
      ~~~~^~~~~~~~~~~~
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:79:6: warning: unused variable 'N' [-Wunused-variable]
  int N = S.size();
      ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 13 ms 512 KB Output is correct
5 Correct 216 ms 6320 KB Output is correct
6 Correct 14 ms 3288 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 212 ms 6320 KB Output is correct
9 Correct 256 ms 6320 KB Output is correct
10 Correct 34 ms 4352 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 13 ms 512 KB Output is correct
5 Correct 216 ms 6320 KB Output is correct
6 Correct 14 ms 3288 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 212 ms 6320 KB Output is correct
9 Correct 256 ms 6320 KB Output is correct
10 Correct 34 ms 4352 KB Output is correct
11 Correct 31 ms 4352 KB Output is correct
12 Correct 31 ms 4352 KB Output is correct
13 Correct 26 ms 4400 KB Output is correct
14 Correct 5 ms 128 KB Output is correct
15 Correct 26 ms 4352 KB Output is correct
16 Correct 9 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
19 Incorrect 71 ms 4352 KB Output isn't correct
20 Halted 0 ms 0 KB -