# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
148472 | White Fairy (#200) | HicCup (FXCUP4_hiccup) | C++17 | 59 ms | 3328 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;
bool can(string & S, int & it, int x) {
int cnt = 0, need = 0;
while (it < S.size()) {
if (cnt > 0 && need == 0) {
--cnt;
need = x;
}
char ch = S[it++];
if (ch == '!') {
if (need > 0) {
--need;
}
}
else if (ch == 'H') {
bool res = can(S, it, x);
if (!res)
return false;
++cnt;
}
else {
return cnt <= 0 && need <= 0;
}
}
return cnt <= 0 && need <= 0;
}
int HicCup(std::string S) {
int N = S.size();
int open = 0;
for (int i = 0; i < N; ++i) {
if (S[i] == 'H')
++open;
else if (S[i] == 'C')
--open;
if (open < 0)
return -1;
}
if (open != 0)
return -1;
if (S[0] == '!')
return -1;
for (int i = 0; i + 1 < N; ++i) {
if (S[i] == 'H' && S[i+1] == '!')
return -1;
}
int low = 0, hi = N;
while (low < hi) {
int mid = (low + hi + 1) >> 1;
int it = 0;
if (can(S, it, mid))
low = mid;
else
hi = mid-1;
}
return low;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |