답안 #148471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148471 2019-09-01T04:29:55 Z USA1(#3634, ecnerwala, scott_wu, ksun48) HicCup (FXCUP4_hiccup) C++17
100 / 100
241 ms 9200 KB
#include "hiccup.h"
#include <bits/stdc++.h>

using namespace std;

int N;
string S;
vector <int> hv, cv, ov;

bool works (int K)
{
    hv.clear();
    cv.clear();
    ov.clear();

    //cout << S << " " << K << "\n";

    int nq = 0;
    bool popk = false;
    for (int i = 0; i < N; i++)
    {
        //cout << i << endl;
        if (S[i] == 'H')
        {
            hv.push_back(nq++);
            popk = false;
        }
        else if (S[i] == 'C')
        {
            cv.push_back(nq++);
            popk = false;
        }
        else
        {
            if (popk) continue;
            ov.push_back(nq++);
        }

        if (hv.size() > 0 && cv.size() > 0)
        {
            int h = hv.back(), c = cv.back();
            //cout << h << " " << c << " " << K << " " << nq << endl;
            if (c == h + 1 && c + K < nq)
            {
                while (ov.size() > 0 && ov.back() > h)
                    ov.pop_back();
                hv.pop_back();
                cv.pop_back();
                popk = true;
                if (hv.size() > 0 && cv.size() > 0 && cv.back() == hv.back() + 1)
                    popk = false;
                nq = h;
            }
        }
    }
    return (hv.size() + cv.size() + ov.size()) == 0;
}

int HicCup(string NOTS) {
    S = NOTS;
    N = S.length();

    if (!works(0))
        return -1;

    int lo = 0, hi = N;
    while (lo < hi)
    {
        int mid = (lo + hi + 1) / 2;
        if (works (mid))
            lo = mid;
        else
            hi = mid - 1;
    }
	return lo;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 13 ms 896 KB Output is correct
5 Correct 227 ms 8412 KB Output is correct
6 Correct 26 ms 4352 KB Output is correct
7 Correct 27 ms 4352 KB Output is correct
8 Correct 241 ms 8412 KB Output is correct
9 Correct 227 ms 8412 KB Output is correct
10 Correct 28 ms 4352 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 13 ms 896 KB Output is correct
5 Correct 227 ms 8412 KB Output is correct
6 Correct 26 ms 4352 KB Output is correct
7 Correct 27 ms 4352 KB Output is correct
8 Correct 241 ms 8412 KB Output is correct
9 Correct 227 ms 8412 KB Output is correct
10 Correct 28 ms 4352 KB Output is correct
11 Correct 26 ms 4352 KB Output is correct
12 Correct 19 ms 4224 KB Output is correct
13 Correct 15 ms 4096 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 16 ms 4352 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 113 ms 8432 KB Output is correct
20 Correct 112 ms 8560 KB Output is correct
21 Correct 100 ms 8560 KB Output is correct
22 Correct 127 ms 8304 KB Output is correct
23 Correct 136 ms 8560 KB Output is correct
24 Correct 113 ms 8608 KB Output is correct
25 Correct 239 ms 8404 KB Output is correct
26 Correct 155 ms 9200 KB Output is correct
27 Correct 98 ms 8552 KB Output is correct
28 Correct 125 ms 8432 KB Output is correct
29 Correct 130 ms 8560 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 13 ms 1324 KB Output is correct
33 Correct 5 ms 384 KB Output is correct