Submission #151601

# Submission time Handle Problem Language Result Execution time Memory
151601 2019-09-03T16:21:30 Z leduykhongngu HicCup (FXCUP4_hiccup) C++17
100 / 100
88 ms 6340 KB
#include <cstdio>
#include <iostream>
#include <cstring>
#include <stack>
#include <cassert>
using namespace std;
#define n ahskjdhakjsfhas
#define S ashfkhdfkhsdkfj
string S = "";
int n;

bool Checkk(int lim)
{
    int cntCur = 0;
    stack<int> cnt;
    stack<char> st;
    #define vedify(x) if ((x) == 0) return false;
    char pre = '#';
    bool done = 0;
    for (char x : S) {
        if (x != '!') {
            if (cntCur >= lim) {
                while (cntCur >= lim) {
                    vedify(st.size() >= 2);
                    vedify(st.top() == 'C');
                    st.pop();
                    vedify(st.top() == 'H');
                    st.pop();
                    done = 0;
                    cntCur -= lim;
                    if (cntCur > 0) {
                        if (st.size() == 0) cntCur = 0;
                        else if (st.top() == 'C') {
                            assert(cnt.size() >= 0);
                            cntCur += cnt.top();
                            cnt.pop();
                            done = 1;
                        }
                        else if (st.top() == 'H') {
                            cntCur = 0;
                        }
                    }
                }
                if (done && st.size() && st.top() == 'C')
                    cnt.push(cntCur);
                // cerr << cntCur << endl;
                // if (x == '#') {
                //     cerr << "lim = "  << lim << endl;
                //     cerr << st.size() << ' ';
                //     while (st.size()) {
                //         cerr << st.top() << ' ';
                //         st.pop();
                //     }
                // }
            }
            else { //cntCur < lim
                if (pre == '!')
                    cnt.push(cntCur);
                cntCur = 0;
            }
            if (x == 'H')
                st.push(x);
            else if (x == 'C') { //x == 'C'
                vedify(st.size() >= 1 && st.top() == 'H');
                st.push(x);
            }
            if (x == '#' && st.size() == 0) return true;
            if (x == '#') return false;
        }
        else { //x == '!'
            vedify(st.size() >= 2 && st.top() == 'C');
            ++cntCur;
        }
        pre = x;
    }
    assert(-1);
    return true;
}

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

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:83:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < tmp.length(); ++i)
                     ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 41 ms 5296 KB Output is correct
6 Correct 27 ms 5296 KB Output is correct
7 Correct 27 ms 5296 KB Output is correct
8 Correct 42 ms 5296 KB Output is correct
9 Correct 41 ms 5308 KB Output is correct
10 Correct 27 ms 5296 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 41 ms 5296 KB Output is correct
6 Correct 27 ms 5296 KB Output is correct
7 Correct 27 ms 5296 KB Output is correct
8 Correct 42 ms 5296 KB Output is correct
9 Correct 41 ms 5308 KB Output is correct
10 Correct 27 ms 5296 KB Output is correct
11 Correct 27 ms 5296 KB Output is correct
12 Correct 26 ms 5296 KB Output is correct
13 Correct 24 ms 5296 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 19 ms 5296 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 44 ms 5296 KB Output is correct
20 Correct 31 ms 5292 KB Output is correct
21 Correct 65 ms 5296 KB Output is correct
22 Correct 58 ms 4192 KB Output is correct
23 Correct 88 ms 6320 KB Output is correct
24 Correct 28 ms 6320 KB Output is correct
25 Correct 38 ms 6340 KB Output is correct
26 Correct 27 ms 6316 KB Output is correct
27 Correct 78 ms 6320 KB Output is correct
28 Correct 86 ms 5268 KB Output is correct
29 Correct 87 ms 6320 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 8 ms 764 KB Output is correct
33 Correct 2 ms 376 KB Output is correct