Submission #149356

# Submission time Handle Problem Language Result Execution time Memory
149356 2019-09-01T06:19:26 Z JeffreyHo(#3776, JeffreyHo) HicCup (FXCUP4_hiccup) C++17
100 / 100
122 ms 11424 KB
#include "hiccup.h"
#include <vector>
#include <bits/stdc++.h>

int HicCup(std::string s) {
    int n = (int)s.size(), c = 0;
    bool b = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'H') c++, b = 1;
        if (s[i] == 'C') c--, b = 1;
        if (c < 0) return -1;
    }
    if (s.empty()) return 0;
    if (s[0] == '!') return -1;
    if (c) return -1;
    for (int i = 1; i < n; i++) if (s[i] == '!' && s[i - 1] == 'H') return -1;
    int l = 0, r = 1890328;
    while (l + 1 < r) {
        int m = (l + r) >> 1, c = 0;
        bool y = 0;
        std::vector<std::pair<int, int>> a = {{-1, -1890328}};
        std::vector<int> b;
        for (int i = 0; i < n; i++) {
            if (s[i] == 'H') b.push_back(i);
            if (s[i] == 'C') c -= m, a.push_back({b.back(), 0}), b.pop_back();
            if (c < -20000328) break;
            if (s[i] == '!') {
                c++;
                a.back().second++;
                if (a.back().second == m) {
                    int b = a.back().first;
                    a.pop_back();
                    if (a.back().first > b) y = 1;
                }
            }
            if (c > 0) c = 0;
        }
        if (c || a.size() > 1 || y) r = m;
        else l = m;
    }
    return l;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:7:10: warning: variable 'b' set but not used [-Wunused-but-set-variable]
     bool b = 0;
          ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 20 ms 996 KB Output is correct
5 Correct 118 ms 11400 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 122 ms 11384 KB Output is correct
9 Correct 118 ms 11424 KB Output is correct
10 Correct 13 ms 3328 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 20 ms 996 KB Output is correct
5 Correct 118 ms 11400 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 122 ms 11384 KB Output is correct
9 Correct 118 ms 11424 KB Output is correct
10 Correct 13 ms 3328 KB Output is correct
11 Correct 19 ms 3328 KB Output is correct
12 Correct 15 ms 3328 KB Output is correct
13 Correct 17 ms 3328 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 14 ms 3328 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 6 ms 560 KB Output is correct
19 Correct 82 ms 3456 KB Output is correct
20 Correct 71 ms 3564 KB Output is correct
21 Correct 83 ms 3328 KB Output is correct
22 Correct 100 ms 3200 KB Output is correct
23 Correct 102 ms 3328 KB Output is correct
24 Correct 82 ms 3776 KB Output is correct
25 Correct 111 ms 10500 KB Output is correct
26 Correct 76 ms 5196 KB Output is correct
27 Correct 87 ms 3328 KB Output is correct
28 Correct 92 ms 3280 KB Output is correct
29 Correct 101 ms 3328 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 128 KB Output is correct
32 Correct 12 ms 640 KB Output is correct
33 Correct 7 ms 384 KB Output is correct