#include "hiccup.h"
using namespace std;
bool valid(string S){
int N = S.size();
bool preH = true;
int t1=0, t2=0;
for(int i=0;i<N;i++){
if (S[i]=='H'){
t1++;
preH = true;
}
else if (S[i]== 'C'){
t2++;
preH = false;
}
else if (S[i]== '!'){
if (preH) return false;
}
else{
return false;
}
if (t1<t2){
return false;
}
}
if (t1!=t2){
return false;
}
return true;
}
int HicCup(std::string S) {
int N = S.size();
int min = 10000000;
if (!valid(S)){
return -1;
}
int t2=0,t3=0;
for(int i=N-1; i>=0; i--){
if (S[i]== 'C'){
t2++;
}
else if (S[i]== '!'){
t3++;
}
if (t2==0){
continue;
}
if (min>(t3/t2)){
min = t3/t2;
}
}
return min;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
27 ms |
4352 KB |
Output is correct |
6 |
Correct |
15 ms |
4352 KB |
Output is correct |
7 |
Correct |
15 ms |
4352 KB |
Output is correct |
8 |
Correct |
29 ms |
4352 KB |
Output is correct |
9 |
Correct |
29 ms |
4352 KB |
Output is correct |
10 |
Correct |
14 ms |
4352 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
27 ms |
4352 KB |
Output is correct |
6 |
Correct |
15 ms |
4352 KB |
Output is correct |
7 |
Correct |
15 ms |
4352 KB |
Output is correct |
8 |
Correct |
29 ms |
4352 KB |
Output is correct |
9 |
Correct |
29 ms |
4352 KB |
Output is correct |
10 |
Correct |
14 ms |
4352 KB |
Output is correct |
11 |
Correct |
16 ms |
4096 KB |
Output is correct |
12 |
Correct |
16 ms |
4352 KB |
Output is correct |
13 |
Correct |
15 ms |
4352 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
15 ms |
4352 KB |
Output is correct |
16 |
Correct |
5 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 |
25 ms |
4224 KB |
Output is correct |
20 |
Incorrect |
23 ms |
4352 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |