#include "hiccup.h"
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v[1000009];
int HicCup(std::string a) {
int n = a.size();
int i, j, k;
for (i = j=k=0; i < n; i++) {
if (a[i] == 'H') {
k++; j = 0;
}
else if (a[i] == 'C') { k--; j = 1; if (k < 0)return -1; }
else {
if (j == 0)return -1;
}
}
if (k > 0) return -1;
int l = 1;
int r = n;
std::string b = a;
b.resize(n + 1);
b[n] = 'X';
int res = n;
int st = 0;
for (i = 0; i < n; i++) {
//printf("%d %d\n", i, st);
if(a[i] == 'H'){
v[st].push_back(0);
st++;
}
else if (a[i] == 'C')
{
if (v[st].size() > 0)
{
int sum = 0;
int cnt = 0;
for (j = v[st].size() - 1; j >= 0; j--)
{
sum += v[st][j];
cnt++;
res = min(res, sum / cnt);
}
}
v[st].clear();
st--;
}
else {
v[st][v[st].size() - 1]++;
}
}
if (v[st].size() > 0)
{
int sum = 0;
int cnt = 0;
for (j = v[st].size() - 1; j >= 0; j--)
{
sum += v[st][j];
cnt++;
res = min(res, sum / cnt);
}
}
v[st].clear();
return res;
}
Compilation message
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:19:6: warning: unused variable 'l' [-Wunused-variable]
int l = 1;
^
hiccup.cpp:20:6: warning: unused variable 'r' [-Wunused-variable]
int r = n;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23844 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is correct |
3 |
Correct |
24 ms |
23928 KB |
Output is correct |
4 |
Correct |
26 ms |
24060 KB |
Output is correct |
5 |
Correct |
51 ms |
29688 KB |
Output is correct |
6 |
Correct |
31 ms |
27640 KB |
Output is correct |
7 |
Correct |
32 ms |
27640 KB |
Output is correct |
8 |
Correct |
50 ms |
29688 KB |
Output is correct |
9 |
Correct |
51 ms |
29620 KB |
Output is correct |
10 |
Correct |
31 ms |
27640 KB |
Output is correct |
11 |
Correct |
25 ms |
23928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23844 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is correct |
3 |
Correct |
24 ms |
23928 KB |
Output is correct |
4 |
Correct |
26 ms |
24060 KB |
Output is correct |
5 |
Correct |
51 ms |
29688 KB |
Output is correct |
6 |
Correct |
31 ms |
27640 KB |
Output is correct |
7 |
Correct |
32 ms |
27640 KB |
Output is correct |
8 |
Correct |
50 ms |
29688 KB |
Output is correct |
9 |
Correct |
51 ms |
29620 KB |
Output is correct |
10 |
Correct |
31 ms |
27640 KB |
Output is correct |
11 |
Correct |
33 ms |
27804 KB |
Output is correct |
12 |
Correct |
32 ms |
27640 KB |
Output is correct |
13 |
Correct |
31 ms |
27640 KB |
Output is correct |
14 |
Correct |
25 ms |
23800 KB |
Output is correct |
15 |
Correct |
31 ms |
27640 KB |
Output is correct |
16 |
Correct |
24 ms |
23800 KB |
Output is correct |
17 |
Correct |
25 ms |
23800 KB |
Output is correct |
18 |
Correct |
25 ms |
24056 KB |
Output is correct |
19 |
Correct |
38 ms |
29752 KB |
Output is correct |
20 |
Correct |
43 ms |
29788 KB |
Output is correct |
21 |
Correct |
39 ms |
29684 KB |
Output is correct |
22 |
Correct |
37 ms |
29304 KB |
Output is correct |
23 |
Correct |
38 ms |
29720 KB |
Output is correct |
24 |
Correct |
39 ms |
29688 KB |
Output is correct |
25 |
Correct |
52 ms |
29688 KB |
Output is correct |
26 |
Correct |
42 ms |
29688 KB |
Output is correct |
27 |
Correct |
38 ms |
29688 KB |
Output is correct |
28 |
Correct |
38 ms |
29432 KB |
Output is correct |
29 |
Correct |
38 ms |
29688 KB |
Output is correct |
30 |
Correct |
24 ms |
23716 KB |
Output is correct |
31 |
Correct |
24 ms |
23804 KB |
Output is correct |
32 |
Correct |
27 ms |
24212 KB |
Output is correct |
33 |
Correct |
25 ms |
23928 KB |
Output is correct |