#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;
int HicCup(std::string S) {
int N = S.size();
int nrH = 0, nrC = 0;
for(auto i : S){
if(i == '!' && (nrH == 0 || nrC == 0)) return -1;
else if(i == 'H') ++nrH;
else if(i == 'C'){
++nrC;
if(nrC > nrH) return -1;
}
}
int st = 0, dr = N;
while(st <= dr){
int mij = (st + dr) / 2;
int nr = 0;
bool ok = true;
for(int i = N - 1; i >= 0 ; --i){
if(S[i] == '!') ++nr;
else if(S[i] == 'C') nr -= mij;
if(nr < 0) {ok = false; break ;}
}
if(ok) st = mij + 1;
else dr = mij - 1;
}
return dr;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
25 ms |
3328 KB |
Output is correct |
6 |
Correct |
20 ms |
3328 KB |
Output is correct |
7 |
Correct |
12 ms |
3328 KB |
Output is correct |
8 |
Correct |
26 ms |
3328 KB |
Output is correct |
9 |
Correct |
25 ms |
3328 KB |
Output is correct |
10 |
Correct |
12 ms |
3328 KB |
Output is correct |
11 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
25 ms |
3328 KB |
Output is correct |
6 |
Correct |
20 ms |
3328 KB |
Output is correct |
7 |
Correct |
12 ms |
3328 KB |
Output is correct |
8 |
Correct |
26 ms |
3328 KB |
Output is correct |
9 |
Correct |
25 ms |
3328 KB |
Output is correct |
10 |
Correct |
12 ms |
3328 KB |
Output is correct |
11 |
Correct |
14 ms |
3328 KB |
Output is correct |
12 |
Correct |
13 ms |
3328 KB |
Output is correct |
13 |
Correct |
19 ms |
3328 KB |
Output is correct |
14 |
Correct |
5 ms |
428 KB |
Output is correct |
15 |
Incorrect |
16 ms |
3328 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |