# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
149445 | 잉여로운 고3 (#200) | HicCup (FXCUP4_hiccup) | C++17 | 43 ms | 3456 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 <bits/stdc++.h>
using namespace std;
int HicCup(string S) {
int N = S.size();
int sum = 0;
for(int i = 0; i < S.size(); i++) {
if(S[i] == 'H') sum++;
else if(S[i] == 'C') sum--;
if(sum < 0) return -1;
}
if(sum != 0) return -1;
int fc = S.size();
for(int i = S.size() - 1; i >= 0; i--) if(S[i] == 'C') fc = i;
if(fc == S.size()) return -1;
for(int i = 0; i < fc; i++) if(S[i] == '!') return -1;
int s = 0, e = S.size() - 1;
while(s < e) {
int m = (s + e + 1) / 2;
int cnt = 0;
bool b = true;
for(int i = S.size() - 1; i >= 0; i--) {
if(S[i] == '!') cnt++;
else if(S[i] == 'C') cnt -= m;
if(cnt < 0) b = false;
}
if(b) s = m;
else e = m - 1;
}
return s;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |