Submission #148659

# Submission time Handle Problem Language Result Execution time Memory
148659 2019-09-01T04:52:51 Z 본인 하지만 안 어림 ㅋㅋ(#3569, gs13105, xdoju, gs13068) HicCup (FXCUP4_hiccup) C++17
100 / 100
76 ms 4352 KB
#include <bits/stdc++.h>
using namespace std; 

#include "hiccup.h"

int HicCup(std::string s) {

	int n = s.size();

    int c = 0;
    for(int i = 0; i < n; i++)
    {
        if(s[i] == 'H')
            c++;
        else if(s[i] == 'C')
            c--;

        if(c < 0)
            return -1;
    }
    if(c != 0)
        return -1;

    s.insert(s.begin(), 'H');
    s.push_back('C');
    n = s.size();

    int l = 0;
    int r = n;
    while(l <= r)
    {
        int x = (l + r + 1) / 2;

        bool ok = 1;
        bool u = 0;
        int t = 0;
        stack<vector<int>> stk;
        stk.push(vector<int>());
        for(int i = 0; i < n; i++)
        {
            if(s[i] == 'H')
            {
                if(i != 0)
                {
                    stk.top().push_back(t);
                    t = 0;
                }

                stk.push(vector<int>());
                u = 0;
            }
            else if(s[i] == 'C')
            {
                stk.top().push_back(t);
                t = 0;

                assert(stk.top()[0] == 0);

                int sz = stk.top().size();
                int cnt = 0;
                for(int j = sz - 1; j >= 1; j--)
                {
                    cnt += stk.top()[j];
                    cnt -= x;
                    if(cnt < 0)
                    {
                        ok = 0;
                        break;
                    }
                }
                if(!ok)
                    break;

                stk.pop();

                u = 1;
            }
            else
            {
                if(!u)
                    return -1;
                t++;
            }
        }

        if(l == r)
        {
            assert(ok);
            return l;
        }

        if(ok)
            l = x;
        else
            r = x - 1;
    }
    assert(0);
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 73 ms 4096 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 12 ms 3328 KB Output is correct
8 Correct 73 ms 4352 KB Output is correct
9 Correct 74 ms 4352 KB Output is correct
10 Correct 13 ms 3328 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 73 ms 4096 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 12 ms 3328 KB Output is correct
8 Correct 73 ms 4352 KB Output is correct
9 Correct 74 ms 4352 KB Output is correct
10 Correct 13 ms 3328 KB Output is correct
11 Correct 13 ms 3328 KB Output is correct
12 Correct 14 ms 3328 KB Output is correct
13 Correct 12 ms 3328 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 14 ms 4352 KB Output is correct
16 Correct 5 ms 128 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 39 ms 4224 KB Output is correct
20 Correct 31 ms 4352 KB Output is correct
21 Correct 63 ms 4352 KB Output is correct
22 Correct 49 ms 3968 KB Output is correct
23 Correct 74 ms 4352 KB Output is correct
24 Correct 24 ms 4352 KB Output is correct
25 Correct 56 ms 4352 KB Output is correct
26 Correct 34 ms 4096 KB Output is correct
27 Correct 68 ms 4352 KB Output is correct
28 Correct 73 ms 4224 KB Output is correct
29 Correct 76 ms 4352 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 11 ms 640 KB Output is correct
33 Correct 5 ms 384 KB Output is correct