답안 #150026

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150026 2019-09-01T07:34:26 Z 이 대회 미분 되나요?(#3668, wookje, edenooo, jms100300) HicCup (FXCUP4_hiccup) C++17
0 / 100
6 ms 384 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();
		}
	}
	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++;
		}
		if (S[i] == 'C')
		{
			if (!v.empty())
			{
				lv[i] = v.back();
				v.pop_back();
			}
			cnt--;
		}
		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:60:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = lo + hi >> 1;
             ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -