제출 #148811

#제출 시각아이디문제언어결과실행 시간메모리
1488111 WA = 5 Push Up (#200)HicCup (FXCUP4_hiccup)C++17
24 / 100
57 ms8192 KiB
#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;

int N;
std::string S;
int myS[1000010];

char myST[1000010], top;
int state[1000010];

bool able(int v)
{
	top = 0;
	for (int i = 0; i < N; i++)
	{
		myST[++top] = S[i];
		if (S[i] == 'H')
			state[top] = 1;
		if (S[i] == 'C')
		{
			if (state[top - 1] == 1)
				state[top] = 2;
			else return false;
		}
		if (S[i] == '!')
		{
			if (state[top - 1] <= 1) top--;
			if (state[top - 1] > 1)
				state[top] = state[top - 1] + 1;
		}

		if (state[top] == v + 2)
			top -= v + 2;
	}

	return state[top] == 0;
}

int HicCup(std::string S_) {
	S = S_;
	N = S.size();

	stack <int> ST;
	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'H') ST.push(i);
		if (S[i] == 'C')
		{
			if (ST.empty()) return -1;
			myS[ST.top()] = i;
			ST.pop();
		}
	}
	if (!ST.empty()) return -1;

	for (int i = 0; i < N; i++)
		if (S[i] == '!')
		{
			if (i == 0) return -1;
			if (S[i - 1] == 'H') return -1;
		}

	int s, e, v;
	s = 0; e = (1 << 20) - 1;
	while (s < e)
	{
		v = (s + e) / 2;
		if (able(v + 1)) s = v + 1;
		else e = v;
	}

	return s;
}

컴파일 시 표준 에러 (stderr) 메시지

hiccup.cpp: In function 'bool able(int)':
hiccup.cpp:17:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   myST[++top] = S[i];
             ^
hiccup.cpp:19:13: warning: array subscript has type 'char' [-Wchar-subscripts]
    state[top] = 1;
             ^
hiccup.cpp:23:14: warning: array subscript has type 'char' [-Wchar-subscripts]
     state[top] = 2;
              ^
hiccup.cpp:30:14: warning: array subscript has type 'char' [-Wchar-subscripts]
     state[top] = state[top - 1] + 1;
              ^
hiccup.cpp:33:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   if (state[top] == v + 2)
                ^
hiccup.cpp:37:18: warning: array subscript has type 'char' [-Wchar-subscripts]
  return state[top] == 0;
                  ^
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…