답안 #150327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150327 2019-09-01T08:09:14 Z HSNU(#3687, joylintp, 147, wiwiho) HicCup (FXCUP4_hiccup) C++17
0 / 100
11 ms 384 KB
#include<bits/stdc++.h>
#include "hiccup.h"

using namespace std;

bool chk(string s)
{
    if (s[0] == '!')
        return false;
    for (int i = 1; i < (int)s.size(); i++)
        if (s[i] == '!' && s[i - 1] == 'H')
            return false;

    stack<char> stk;
    for (int i = 0; i < (int)s.size(); i++)
        if (s[i] == '!')
            continue;
        else if (stk.empty())
            stk.push(s[i]);
        else if (stk.top() == 'H' && s[i] == 'C')
            stk.pop();
        else
            stk.push(s[i]);

    return stk.empty();
}

int HicCup(string S)
{
	long long N = S.size();

	if (!chk(S))
        return -1;

    long long ans = N;

    stack<long long> stk;
    string s = "H" + S + "C";
    for (int i = 0; i < (int)s.size(); i++)
        if (s[i] == 'H')
            stk.push(-1);
        else if (s[i] == 'C')
        {
            long long ttl = 0, cnt = 0;
            while (stk.top() != -1)
                ttl += stk.top(), cnt++, stk.pop();
            stk.pop();

            if (cnt)
                ans = min(ans, ttl / cnt);
        }
        else
        {
            int cnt = 0;
            while (s[i] == '!')
                cnt++, i++;
            i--;
            stk.push(cnt);
        }

	return ans;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:39:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 0; i < (int)s.size(); i++)
     ^~~
hiccup.cpp:61:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  return ans;
  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -