# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
148878 | | 코딩은 체육과목입니다 (#200) | HicCup (FXCUP4_hiccup) | C++17 | | 35 ms | 7396 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>
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 (stderr)
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++){
~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |