# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151039 | dongwon0427 | HicCup (FXCUP4_hiccup) | C++17 | 116 ms | 43660 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 <stack>
#include <vector>
int par[1000005];
int fr[1000005];
int len[1000005];
std::vector<int> child[1000005];
int dfs(int idx) {
int mn = 1e6;
int sum = 0;
for(int i=0;i<child[idx].size();i++) {
sum += len[child[idx][i]];
mn = std::min(mn, sum/(i+1));
}
return mn;
}
int HicCup(std::string S) {
int n = S.size();
std::stack<int> ST;
ST.push(1);
for(int i=0;i<n;i++) {
if(S[i] == 'H') {
par[i+2] = ST.top();
ST.push(i+2);
} else if(S[i] == 'C') {
if(ST.top() == 1) return -1;
fr[i] = ST.top();
ST.pop();
}
}
if(ST.size() != 1) return -1;
for(int i=0;i<n;i++) {
if(S[i] == 'C') {
if(fr[i] == 0) return -1;
}
}
for(int i=0;i<n;i++) {
if(S[i] == 'C') {
for(int j=i+1;j<n;j++) {
if(S[j] != '!') break;
len[fr[i]]++;
}
}
}
for(int i=0;i+1<n;i++) {
if(S[i] == 'H') {
if(S[i+1] == '!') return -1;
}
}
for(int i=n-1;i>=0;i--) {
if(S[i] == 'H') {
child[par[i+2]].push_back(i+2);
}
}
/*for(int i=0;i<n;i++) {
if(S[i] == 'H') {
printf("%d %d\n",i+2,len[i+2]);
}
}
for(int i=1;i<=n+2;i++) {
if(child[i].size()) {
printf("%d ",i);
for(int j : child[i]) printf("%d ",j);
printf("\n");
}
}*/
return dfs(1);;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |