#include "hiccup.h"
#include<vector>
#include<deque>
using namespace std;
bool f(string& S, int X){
deque<int>Q(S.begin(),S.end());
vector<int>V{-1};
bool z=0;
while(!Q.empty()){
char q=Q.front();
Q.pop_front();
if(q=='H'){
z=0;
V.emplace_back(0);
}else if(q=='C'){
z=0;
if(V.back()!=0)return false;
V.back()=1;
if(X==0)V.pop_back();
}else{
if(V.back()<1){
if(!z)return false;
continue;
}
V.back()++;
if(V.back()==X+1){
V.pop_back();
z=1;
}
}
}
if(V.size()>1)return false;
return true;
}
int HicCup(std::string S) {
int N = S.size();
int l=-1,r=N;
while(l<r){
int X=(l+r+1)/2;
if(f(S,X))l=X;
else r=X-1;
}
return l;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
544 KB |
Output is correct |
5 |
Correct |
34 ms |
8192 KB |
Output is correct |
6 |
Correct |
23 ms |
8288 KB |
Output is correct |
7 |
Correct |
24 ms |
8244 KB |
Output is correct |
8 |
Correct |
28 ms |
8276 KB |
Output is correct |
9 |
Correct |
29 ms |
8276 KB |
Output is correct |
10 |
Correct |
23 ms |
8180 KB |
Output is correct |
11 |
Correct |
1 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
544 KB |
Output is correct |
5 |
Correct |
34 ms |
8192 KB |
Output is correct |
6 |
Correct |
23 ms |
8288 KB |
Output is correct |
7 |
Correct |
24 ms |
8244 KB |
Output is correct |
8 |
Correct |
28 ms |
8276 KB |
Output is correct |
9 |
Correct |
29 ms |
8276 KB |
Output is correct |
10 |
Correct |
23 ms |
8180 KB |
Output is correct |
11 |
Correct |
1 ms |
292 KB |
Output is correct |
12 |
Correct |
22 ms |
8276 KB |
Output is correct |
13 |
Correct |
23 ms |
8276 KB |
Output is correct |
14 |
Correct |
25 ms |
8276 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
24 ms |
8300 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
292 KB |
Output is correct |
19 |
Correct |
2 ms |
852 KB |
Output is correct |
20 |
Correct |
51 ms |
8296 KB |
Output is correct |
21 |
Correct |
39 ms |
8276 KB |
Output is correct |
22 |
Correct |
58 ms |
8304 KB |
Output is correct |
23 |
Correct |
52 ms |
7852 KB |
Output is correct |
24 |
Correct |
71 ms |
8276 KB |
Output is correct |
25 |
Correct |
33 ms |
8276 KB |
Output is correct |
26 |
Incorrect |
23 ms |
8188 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |