Submission #149158

# Submission time Handle Problem Language Result Execution time Memory
149158 2019-09-01T05:50:53 Z mit한의대지망생(#3602, TAMREF, imeimi2000, suzy) HicCup (FXCUP4_hiccup) C++17
100 / 100
90 ms 16224 KB
#include "hiccup.h"
#include <algorithm>
#include <vector>
#include <tuple>

using namespace std;
typedef pair<int, int> pii;

int n;
char S[1000001];
int nxt[1000002];
int prv[1000002];
vector<pii> P;

bool check(int x) {
    for (int i = 1; i <= n; ++i) {
        nxt[i] = i + 1;
        prv[i] = i - 1;
    }
    for (pii _i : P) {
        int a, b;
        tie(a, b) = _i;
        int cnt = 0, i;
        for (i = nxt[b]; cnt < x && i <= n && S[i] == '!'; i = nxt[i], ++cnt);
        if (cnt < x) return 0;
        if (nxt[a] == b) {
            nxt[prv[a]] = i;
            prv[i] = prv[a];
        }
        else {
            nxt[prv[a]] = nxt[a];
            prv[nxt[a]] = prv[a];
            nxt[prv[b]] = i;
            prv[i] = prv[b];
        }
    }
    return 1;
}

int HicCup(string _S) {
    n = _S.length();
    vector<int> st;
    S[0] = 'H';
    for (int i = 0; i < n; ++i) {
        S[i + 1] = _S[i];
        if (S[i + 1] == 'H') st.push_back(i + 1);
        else if (S[i + 1] == 'C') {
            if (st.empty()) return -1;
            P.emplace_back(st.back(), i + 1);
            st.pop_back();
        }
        if (S[i] == 'H' && S[i + 1] == '!') return -1;
    }
    if (!st.empty()) return -1;
    if (P.empty()) return -1;
    int s = 0, e = n;
    sort(P.begin(), P.end(), [&](pii a, pii b) {
        return a.first > b.first;
    });
    while (s < e) {
        int m = (s + e + 1) / 2;
        if (check(m)) s = m;
        else e = m - 1;
    }
    return s;
}
# Verdict Execution time Memory 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 8 ms 1148 KB Output is correct
5 Correct 82 ms 16224 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 13 ms 3200 KB Output is correct
8 Correct 84 ms 16224 KB Output is correct
9 Correct 77 ms 16096 KB Output is correct
10 Correct 14 ms 3328 KB Output is correct
11 Correct 5 ms 128 KB Output is correct
# Verdict Execution time Memory 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 8 ms 1148 KB Output is correct
5 Correct 82 ms 16224 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 13 ms 3200 KB Output is correct
8 Correct 84 ms 16224 KB Output is correct
9 Correct 77 ms 16096 KB Output is correct
10 Correct 14 ms 3328 KB Output is correct
11 Correct 16 ms 4600 KB Output is correct
12 Correct 15 ms 4348 KB Output is correct
13 Correct 14 ms 3456 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 13 ms 3328 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 47 ms 12032 KB Output is correct
20 Correct 45 ms 12288 KB Output is correct
21 Correct 48 ms 12160 KB Output is correct
22 Correct 70 ms 11520 KB Output is correct
23 Correct 90 ms 12160 KB Output is correct
24 Correct 44 ms 12412 KB Output is correct
25 Correct 72 ms 15200 KB Output is correct
26 Correct 47 ms 12968 KB Output is correct
27 Correct 47 ms 12160 KB Output is correct
28 Correct 66 ms 11776 KB Output is correct
29 Correct 79 ms 12160 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 9 ms 1280 KB Output is correct
33 Correct 5 ms 128 KB Output is correct