#include "hiccup.h"
#include <string.h>
int t[1000003];
int cur[1000003];
int len;
int doable(std::string S, int x)
{
int n = S.length();
int cur_len = 0;
memset(t, 0, sizeof(t));
memset(cur, 0, sizeof(cur));
len = 0;
int erasing = 0;
for(int i=0;i<n;i++)
{
t[len] = S[i];
cur[len] = (S[i] == '!' ? (len ? cur[len-1]+1 : 1) : 0);
len++;
if(erasing && len >= 2 && t[len-2] == 'H' && t[len-1] == '!') len--;
else if(cur[len-1] >= x && len >= x+2 && t[len-x-2] == 'H' && t[len-x-1] == 'C')
{
len -= x+2;
erasing = 1;
}
else erasing = 0;
}
for(int i=0;i<len;i++)
{
if(t[i] != '!') return 0;
}
return 1;
}
int HicCup(std::string S) {
if(S.length() && S[0] == '!') return -1;
int l = 0;
int r = S.length()+1;
if(!doable(S, 0))
{
return -1;
}
while(l<r)
{
int m = (l+r)/2;
if(doable(S, m)) l = m+1;
else r = m;
}
return l-1;
}
Compilation message
hiccup.cpp: In function 'int doable(std::__cxx11::string, int)':
hiccup.cpp:9:9: warning: unused variable 'cur_len' [-Wunused-variable]
int cur_len = 0;
^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
10 ms |
8192 KB |
Output is correct |
4 |
Correct |
25 ms |
8320 KB |
Output is correct |
5 |
Correct |
130 ms |
12160 KB |
Output is correct |
6 |
Correct |
27 ms |
12160 KB |
Output is correct |
7 |
Correct |
27 ms |
12160 KB |
Output is correct |
8 |
Correct |
131 ms |
11948 KB |
Output is correct |
9 |
Correct |
134 ms |
12160 KB |
Output is correct |
10 |
Correct |
26 ms |
12160 KB |
Output is correct |
11 |
Correct |
10 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
10 ms |
8192 KB |
Output is correct |
4 |
Correct |
25 ms |
8320 KB |
Output is correct |
5 |
Correct |
130 ms |
12160 KB |
Output is correct |
6 |
Correct |
27 ms |
12160 KB |
Output is correct |
7 |
Correct |
27 ms |
12160 KB |
Output is correct |
8 |
Correct |
131 ms |
11948 KB |
Output is correct |
9 |
Correct |
134 ms |
12160 KB |
Output is correct |
10 |
Correct |
26 ms |
12160 KB |
Output is correct |
11 |
Correct |
28 ms |
12160 KB |
Output is correct |
12 |
Correct |
23 ms |
12160 KB |
Output is correct |
13 |
Correct |
23 ms |
12160 KB |
Output is correct |
14 |
Correct |
9 ms |
8192 KB |
Output is correct |
15 |
Correct |
24 ms |
12160 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
17 |
Correct |
10 ms |
8192 KB |
Output is correct |
18 |
Correct |
11 ms |
8448 KB |
Output is correct |
19 |
Correct |
135 ms |
12076 KB |
Output is correct |
20 |
Correct |
136 ms |
11948 KB |
Output is correct |
21 |
Correct |
135 ms |
12160 KB |
Output is correct |
22 |
Correct |
124 ms |
11952 KB |
Output is correct |
23 |
Correct |
129 ms |
12160 KB |
Output is correct |
24 |
Correct |
134 ms |
12160 KB |
Output is correct |
25 |
Correct |
208 ms |
12160 KB |
Output is correct |
26 |
Correct |
159 ms |
12180 KB |
Output is correct |
27 |
Correct |
131 ms |
12160 KB |
Output is correct |
28 |
Correct |
124 ms |
12032 KB |
Output is correct |
29 |
Correct |
132 ms |
12068 KB |
Output is correct |
30 |
Correct |
12 ms |
8064 KB |
Output is correct |
31 |
Correct |
17 ms |
7936 KB |
Output is correct |
32 |
Correct |
34 ms |
8448 KB |
Output is correct |
33 |
Correct |
10 ms |
8192 KB |
Output is correct |