답안 #149061

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149061 2019-09-01T05:39:47 Z mit한의대지망생(#3602, TAMREF, imeimi2000, suzy) HicCup (FXCUP4_hiccup) C++17
24 / 100
61 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;
    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 (i > 0 && S[i - 1] == 'H' && S[i] == '!') 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.second > b.second;
    });
    while (s < e) {
        int m = (s + e + 1) / 2;
        if (check(m)) s = m;
        else e = m - 1;
    }
    return s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 1148 KB Output is correct
5 Correct 59 ms 16100 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 61 ms 16224 KB Output is correct
9 Correct 54 ms 16100 KB Output is correct
10 Correct 12 ms 3288 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 1148 KB Output is correct
5 Correct 59 ms 16100 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 61 ms 16224 KB Output is correct
9 Correct 54 ms 16100 KB Output is correct
10 Correct 12 ms 3288 KB Output is correct
11 Correct 15 ms 4600 KB Output is correct
12 Correct 19 ms 4220 KB Output is correct
13 Correct 13 ms 3456 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 13 ms 3328 KB Output is correct
16 Incorrect 5 ms 344 KB Output isn't correct
17 Halted 0 ms 0 KB -