#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
char str[1000002];
bool able(int x){
vector<int> stk;
bool last = 0; /// 마지막이 느낌표
for(int i=1; i<=n; i++){
if(str[i] == 'H') stk.push_back(-1), last = 0;
else if(str[i] == 'C'){
if(stk.empty() || stk.back() != -1) return false;
stk.back()++;
if(x==0){
last = 1;
stk.pop_back();
}
else last = 0;
}
else{
if(stk.empty() || stk.back() == -1){
if(last) {}
else return false;
}
else{
stk.back()++;
if(stk.back() >= x) stk.pop_back(), last = 1;
else last = 0;
}
}
}
return stk.empty();
}
int HicCup(string S){
n = S.size();
for(int i=1; i<=n; i++) str[i] = S[i-1];
int L = 0, R = n, ANS = -1;
while(L<=R){
int M = (L+R)/2;
if(able(M)) ANS = M, L = M+1;
else R = M-1;
}
return ANS;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
10 ms |
5144 KB |
Output is correct |
6 |
Correct |
6 ms |
5180 KB |
Output is correct |
7 |
Correct |
5 ms |
5204 KB |
Output is correct |
8 |
Correct |
10 ms |
5172 KB |
Output is correct |
9 |
Correct |
10 ms |
5176 KB |
Output is correct |
10 |
Correct |
5 ms |
5192 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
10 ms |
5144 KB |
Output is correct |
6 |
Correct |
6 ms |
5180 KB |
Output is correct |
7 |
Correct |
5 ms |
5204 KB |
Output is correct |
8 |
Correct |
10 ms |
5172 KB |
Output is correct |
9 |
Correct |
10 ms |
5176 KB |
Output is correct |
10 |
Correct |
5 ms |
5192 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
5184 KB |
Output is correct |
13 |
Correct |
7 ms |
5328 KB |
Output is correct |
14 |
Correct |
8 ms |
5140 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
5144 KB |
Output is correct |
17 |
Correct |
0 ms |
316 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
24 ms |
5204 KB |
Output is correct |
21 |
Correct |
10 ms |
5212 KB |
Output is correct |
22 |
Correct |
32 ms |
5200 KB |
Output is correct |
23 |
Correct |
36 ms |
4880 KB |
Output is correct |
24 |
Correct |
54 ms |
5204 KB |
Output is correct |
25 |
Correct |
9 ms |
5204 KB |
Output is correct |
26 |
Correct |
10 ms |
5144 KB |
Output is correct |
27 |
Correct |
10 ms |
5184 KB |
Output is correct |
28 |
Correct |
40 ms |
5188 KB |
Output is correct |
29 |
Correct |
52 ms |
5060 KB |
Output is correct |
30 |
Correct |
53 ms |
5112 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
312 KB |
Output is correct |
33 |
Correct |
4 ms |
596 KB |
Output is correct |