#include <bits/stdc++.h>
#include "hiccup.h"
//~ #include "grader.cpp"
using namespace std;
const int N = 1000001;
int n;
string s;
vector <int> h;
bool valid(){
int o = 0;
for(auto &i : s){
o += i == 'H';
o -= i == 'C';
if(o < 0) return 0;
}
if(o) return 0;
for(auto &i : s){
if(i == 'H') o = 0;
else if(i == 'C') o = 1;
else if(o == 0) return 0;
}
return 1;
}
int HicCup(std::string S) {
s = S;
n = s.size();
if(!valid() || s == string(n, '!')) return -1;
h.resize(n);
assert(s[0] == 'H');
h[0] = 1;
for(int i = 1 ; i < n ; i++){
h[i] = h[i - 1];
if(s[i] == 'H') h[i]++;
else if(s[i] == 'C') h[i]--;
}
vector <int> exs(n), cs(n);
int ans = n;
for(int i = n - 1 ; i >= 0 ; i--){
if(s[i] == '!') exs[h[i]]++;
else if(s[i] == 'C'){
cs[h[i]]++;
ans = min(ans, exs[h[i]] / cs[h[i]]);
}
}
return ans;
}
# |
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 |
6 ms |
1024 KB |
Output is correct |
5 |
Correct |
47 ms |
16036 KB |
Output is correct |
6 |
Correct |
13 ms |
4352 KB |
Output is correct |
7 |
Correct |
14 ms |
4352 KB |
Output is correct |
8 |
Correct |
44 ms |
16044 KB |
Output is correct |
9 |
Correct |
44 ms |
16036 KB |
Output is correct |
10 |
Correct |
13 ms |
4312 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 |
6 ms |
1024 KB |
Output is correct |
5 |
Correct |
47 ms |
16036 KB |
Output is correct |
6 |
Correct |
13 ms |
4352 KB |
Output is correct |
7 |
Correct |
14 ms |
4352 KB |
Output is correct |
8 |
Correct |
44 ms |
16044 KB |
Output is correct |
9 |
Correct |
44 ms |
16036 KB |
Output is correct |
10 |
Correct |
13 ms |
4312 KB |
Output is correct |
11 |
Correct |
16 ms |
4352 KB |
Output is correct |
12 |
Correct |
13 ms |
4352 KB |
Output is correct |
13 |
Correct |
15 ms |
4224 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
17 ms |
4352 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
7 ms |
640 KB |
Output is correct |
19 |
Correct |
29 ms |
16044 KB |
Output is correct |
20 |
Incorrect |
34 ms |
16044 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |