Submission #151521

# Submission time Handle Problem Language Result Execution time Memory
151521 2019-09-03T13:35:53 Z leduykhongngu HicCup (FXCUP4_hiccup) C++17
0 / 100
2 ms 256 KB
#include <cstdio>
#include <iostream>
#include <cstring>
#include <stack>
using namespace std;

string S = "";
int n;

bool Check(int x)
{
    stack<char> st;
    stack<int> cnt;
    int cur = 0; bool chk = true;
    for (int i = 0; i < n; ++i)
    {
//        cout << S[i] << ' ' << cur << endl;
        if (S[i] != '!')
        {
            st.push(S[i]);
            if(cur) cnt.push(cur);
            cur = 0;
        }
        else
        {
            if (chk) return false;
            if (st.size() && st.top() != 'H')
            {
                ++cur;
                st.push(S[i]);
            }
        }
        
        if (cur == x)
        {
            for (int i = 1; i <= x; ++i)
                if (st.top() == '!') st.pop();
                else return false;
            while (st.size() && st.top() == '!')
                st.pop();
            if (st.size() && st.top() == 'C') st.pop();
            else return false;
            if (st.size() && st.top() == 'H') st.pop();
            else return false;
            if (cnt.empty()) cur = 0;
            else 
            {
                cur = cnt.top();
                cnt.pop();
            }
        }
        chk = !((S[i] == 'C') || (S[i] == '!'));
    }
    return st.empty();
}

int HicCup(std::string tmp)
{
    for (int i = 0; i < tmp.length(); ++i)
    {
        S.push_back(tmp[i]);
        if (tmp[i] == 'C') S.push_back('!');
    }
    
    n = S.length();
    
//    cout << Check(1);
    
    int lef = 0, rig = n, ans = -1;
    while (lef <= rig)
    {
        int mid = lef + rig >> 1;
        if (Check(mid))
        {
            ans = max(ans, mid);
            lef = mid + 1;
        }
        else rig = mid - 1;
    }
    if (ans != -1) --ans;
    cout << ans;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:59:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < tmp.length(); ++i)
                     ~~^~~~~~~~~~~~~~
hiccup.cpp:72:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = lef + rig >> 1;
                   ~~~~^~~~~
hiccup.cpp:82:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -