# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
150768 | | HSNU (#200) | HicCup (FXCUP4_hiccup) | C++17 | | 61 ms | 4372 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<bits/stdc++.h>
#include "hiccup.h"
using namespace std;
bool chk(string s)
{
if (s[0] == '!')
return false;
for (int i = 1; i < (int)s.size(); i++)
if (s[i] == '!' && s[i - 1] == 'H')
return false;
stack<char> stk;
for (int i = 0; i < (int)s.size(); i++)
if (s[i] == '!')
continue;
else if (stk.empty())
stk.push(s[i]);
else if (stk.top() == 'H' && s[i] == 'C')
stk.pop();
else
stk.push(s[i]);
return stk.empty();
}
int HicCup(string s)
{
if (!chk(s))
return -1;
int ans = 1e9;
stack<int> stk;
for (int i = 0; i < (int)s.size(); i++)
{
if (s[i] == 'H')
stk.push(-1);
else
{
int ttl = 0, cnt = 0;
vector<int> quu;
while (stk.top() != -1)
quu.push_back(stk.top()), ttl += stk.top(), cnt++, stk.pop();
stk.pop();
if (cnt)
{
int avg = ttl / cnt;
for (int i = 0; i < cnt - 1; i++)
if (quu[i] < avg)
ans = min(ans, quu[i]);
else
quu[i + 1] += quu[i] - avg, quu[i] = avg;
ans = min(ans, min(quu[cnt - 1], avg));
}
i++;
cnt = 0;
while (s[i] == '!' && i < (int)s.size())
cnt++, i++;
i--;
stk.push(cnt);
}
}
int ttl = 0, cnt = 0;
vector<int> quu;
while (!stk.empty())
quu.push_back(stk.top()), ttl += stk.top(), cnt++, stk.pop();
if (cnt)
{
int avg = ttl / cnt;
for (int i = 0; i < cnt - 1; i++)
if (quu[i] < avg)
ans = min(ans, quu[i]);
else
quu[i + 1] += quu[i] - avg, quu[i] = avg;
ans = min(ans, min(quu[cnt - 1], avg));
}
return (int)ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |