# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
150990 | pichulia | HicCup (FXCUP4_hiccup) | C++17 | 52 ms | 29788 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |