| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 151521 | leduykhongngu | HicCup (FXCUP4_hiccup) | C++17 | 2 ms | 256 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
