#include "hiccup.h"
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
bool mycheck(vector<ll> Vu, int mi) {
reverse(all(Vu));
ll cur = 0;
for (auto it : Vu) {
cur -= mi;
cur += it;
if (cur < 0) return false;
}
return true;
}
int HicCup(std::string S) {
int N = S.size(), i, j;
int c = 0;
for (int i = 0; i < N; i++) {
if (S[i] == 'H') c++;
if (S[i] == 'C') c--;
if (c < 0) return -1;
}
if (c != 0) return -1;
int p = N;
for (int i = N - 1; i >= 0; i--) if (S[i] == 'C') p = i;
for (int i = 0; i < p; i++) if (S[i] == '!') return -1;
for (int i = 0; i + 1 < N; i++) if (S[i] == 'H' && S[i + 1] == '!') return -1;
int st = 0, en = INF, mi, rv = -1;
while (st <= en) {
mi = (st + en) / 2;
vector <vector<ll>> Vr;
vector <ll> Vu;
Vr.push_back(Vu);
int i;
for (i = 0; i < N; i++) {
if (S[i] == 'H') {
Vu.clear();
Vr.push_back(Vu);
}
else if (S[i] == 'C') {
if (!mycheck(Vr.back(), mi)) break;
Vr.pop_back();
Vr.back().push_back(0);
}
else Vr.back().back()++;
}
if (i >= N && mycheck(Vr.back(), mi)) {
rv = mi;
st = mi + 1;
}
else en = mi - 1;
}
return rv;
}
Compilation message
hiccup.cpp:25:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning(disable:4996)
hiccup.cpp:26:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/STACK:336777216")
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:68:20: warning: unused variable 'i' [-Wunused-variable]
int N = S.size(), i, j;
^
hiccup.cpp:68:23: warning: unused variable 'j' [-Wunused-variable]
int N = S.size(), i, j;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
8 ms |
512 KB |
Output is correct |
5 |
Correct |
76 ms |
3328 KB |
Output is correct |
6 |
Correct |
14 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
75 ms |
3448 KB |
Output is correct |
9 |
Correct |
72 ms |
3328 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 |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
8 ms |
512 KB |
Output is correct |
5 |
Correct |
76 ms |
3328 KB |
Output is correct |
6 |
Correct |
14 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
75 ms |
3448 KB |
Output is correct |
9 |
Correct |
72 ms |
3328 KB |
Output is correct |
10 |
Correct |
13 ms |
3328 KB |
Output is correct |
11 |
Correct |
14 ms |
3200 KB |
Output is correct |
12 |
Correct |
15 ms |
3328 KB |
Output is correct |
13 |
Correct |
14 ms |
3200 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
15 ms |
3328 KB |
Output is correct |
16 |
Correct |
6 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 |
39 ms |
3328 KB |
Output is correct |
20 |
Correct |
29 ms |
3500 KB |
Output is correct |
21 |
Correct |
74 ms |
3328 KB |
Output is correct |
22 |
Correct |
67 ms |
3200 KB |
Output is correct |
23 |
Correct |
109 ms |
3328 KB |
Output is correct |
24 |
Correct |
27 ms |
3704 KB |
Output is correct |
25 |
Correct |
61 ms |
3448 KB |
Output is correct |
26 |
Correct |
37 ms |
3832 KB |
Output is correct |
27 |
Correct |
86 ms |
3328 KB |
Output is correct |
28 |
Correct |
99 ms |
3200 KB |
Output is correct |
29 |
Correct |
103 ms |
3328 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
13 ms |
632 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |