#include "hiccup.h"
#include <vector>
using namespace std;
int HicCup(std::string S) {
vector<int> v1, v2;
vector<vector<int>> vv;
int N = S.size();
int st = 0;
int maxst = 0;
for(int i=0;i<N;i++){
if(S[i]=='H') st++;
else if(S[i]=='C'){
st--;
v1.push_back(0);
v2.push_back(st);
}
else{
if(i==0 || S[i-1] == 'H') return -1;
v1[v1.size()-1]++;
}
if(st<0) return -1;
maxst = max(maxst,st);
}
if(st!=0) return -1;
for(int i=0;i<maxst;i++) vv.push_back(vector<int>());
int idx = 0;
int ans = 10000000;
for(int i=0;i<v1.size();i++){
if(idx > v2[i]){
vv[v2[i]].push_back(v1[i]);
int tot = 0, cnt = 0;
while(!vv[idx].empty()){
cnt++;
tot += vv[idx].back();
vv[idx].pop_back();
ans = min(ans,tot/cnt);
}
}
else{
vv[v2[i]].push_back(v1[i]);
}
idx = v2[i];
}
int tot = 0, cnt = 0;
while(!vv[0].empty()){
cnt++;
tot += vv[0].back();
vv[0].pop_back();
ans = min(ans,tot/cnt);
}
return ans;
}
Compilation message
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:33:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v1.size();i++){
~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
896 KB |
Output is correct |
5 |
Correct |
34 ms |
7396 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
35 ms |
7396 KB |
Output is correct |
9 |
Correct |
34 ms |
7388 KB |
Output is correct |
10 |
Correct |
13 ms |
3328 KB |
Output is correct |
11 |
Correct |
5 ms |
372 KB |
Output is 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 |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
896 KB |
Output is correct |
5 |
Correct |
34 ms |
7396 KB |
Output is correct |
6 |
Correct |
13 ms |
3328 KB |
Output is correct |
7 |
Correct |
13 ms |
3328 KB |
Output is correct |
8 |
Correct |
35 ms |
7396 KB |
Output is correct |
9 |
Correct |
34 ms |
7388 KB |
Output is correct |
10 |
Correct |
13 ms |
3328 KB |
Output is correct |
11 |
Correct |
17 ms |
4348 KB |
Output is correct |
12 |
Correct |
16 ms |
3840 KB |
Output is correct |
13 |
Correct |
14 ms |
3328 KB |
Output is correct |
14 |
Correct |
5 ms |
128 KB |
Output is correct |
15 |
Correct |
13 ms |
3328 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Correct |
7 ms |
512 KB |
Output is correct |
19 |
Correct |
19 ms |
3328 KB |
Output is correct |
20 |
Correct |
18 ms |
3584 KB |
Output is correct |
21 |
Correct |
17 ms |
3328 KB |
Output is correct |
22 |
Correct |
17 ms |
3072 KB |
Output is correct |
23 |
Correct |
18 ms |
3328 KB |
Output is correct |
24 |
Correct |
18 ms |
3712 KB |
Output is correct |
25 |
Correct |
32 ms |
6636 KB |
Output is correct |
26 |
Correct |
21 ms |
4348 KB |
Output is correct |
27 |
Correct |
17 ms |
3328 KB |
Output is correct |
28 |
Correct |
16 ms |
3200 KB |
Output is correct |
29 |
Correct |
17 ms |
3328 KB |
Output is correct |
30 |
Correct |
5 ms |
336 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
6 ms |
640 KB |
Output is correct |
33 |
Correct |
5 ms |
372 KB |
Output is correct |