#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, f = 0;
bool ok = true;
for(int i = N - 1; i >= 0 ; --i){
if(S[i] == '!') ++nr;
else if(S[i] == 'C'){
nr -= mij;
if(f == 0 && nr > 0) nr = 0, f = 1;
}
if(nr < 0) {ok = false; break ;}
}
if(ok) st = mij + 1;
else dr = mij - 1;
}
return dr;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 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 |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
25 ms |
3328 KB |
Output is correct |
9 |
Correct |
25 ms |
3456 KB |
Output is correct |
10 |
Correct |
12 ms |
3328 KB |
Output is correct |
11 |
Incorrect |
6 ms |
304 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 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 |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
25 ms |
3328 KB |
Output is correct |
9 |
Correct |
25 ms |
3456 KB |
Output is correct |
10 |
Correct |
12 ms |
3328 KB |
Output is correct |
11 |
Correct |
15 ms |
3328 KB |
Output is correct |
12 |
Correct |
13 ms |
3328 KB |
Output is correct |
13 |
Correct |
12 ms |
3328 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Incorrect |
14 ms |
3328 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |