Submission #150102

# Submission time Handle Problem Language Result Execution time Memory
150102 2019-09-01T07:43:20 Z 이 대회 미분 되나요?(#3668, wookje, edenooo, jms100300) HicCup (FXCUP4_hiccup) C++17
24 / 100
42 ms 8192 KB
#include "hiccup.h"
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int N;
string s;
int lv[1000101];

bool f(int K)
{
	vector<pair<int, int> > v;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'C')
		{
			while (!v.empty() && v.back().first > lv[i])
				return false;
			v.push_back({ lv[i], 0 });
			while (!v.empty() && v.back().second >= K) v.pop_back();
		}
		else if (s[i] == '!')
		{
			if (!v.empty()) v.back().second++;
			while (!v.empty() && v.back().second >= K) v.pop_back();
		}
	}
	while (!v.empty())
	{
		if (v.back().second < K) return false;
		v.pop_back();
	}
	return true;
}

int HicCup(std::string S) {
	vector<int> v;
	N = S.size();
	s = S;
	int cnt = 0;
	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'H')
		{
			v.push_back(cnt);
			cnt++;
		}
		else if (S[i] == 'C')
		{
			if (!v.empty())
			{
				lv[i] = v.back();
				v.pop_back();
			}
			cnt--;
		}
		else
		{
			if (cnt == 0 || S[i - 1] == 'H') return -1;
		}

		if (cnt < 0) return -1;
	}
	if (cnt > 0) return -1;

	int lo = 0, hi = 1000001;
	for (int i = 0; i < 21; i++)
	{
		int mid = lo + hi >> 1;
		if (f(mid)) lo = mid;
		else hi = mid;
	}
	return lo;
}

Compilation message

hiccup.cpp: In function 'bool f(int)':
hiccup.cpp:14: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:70:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = lo + hi >> 1;
             ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 41 ms 8192 KB Output is correct
6 Correct 14 ms 4224 KB Output is correct
7 Correct 15 ms 4352 KB Output is correct
8 Correct 40 ms 8192 KB Output is correct
9 Correct 42 ms 8192 KB Output is correct
10 Correct 13 ms 4348 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 41 ms 8192 KB Output is correct
6 Correct 14 ms 4224 KB Output is correct
7 Correct 15 ms 4352 KB Output is correct
8 Correct 40 ms 8192 KB Output is correct
9 Correct 42 ms 8192 KB Output is correct
10 Correct 13 ms 4348 KB Output is correct
11 Correct 14 ms 4352 KB Output is correct
12 Correct 14 ms 4224 KB Output is correct
13 Correct 14 ms 4352 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 13 ms 4268 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Incorrect 13 ms 4224 KB Output isn't correct
20 Halted 0 ms 0 KB -