# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
150786 | 오리버스부릉부릉 (#200) | HicCup (FXCUP4_hiccup) | C++17 | 24 ms | 3328 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "hiccup.h"
#include <stack>
#include <vector>
using namespace std;
int HicCup(std::string S) {
bool flag = false;
int N = S.size();
int sp, wp;
stack<int> sta;
for (int i = 0; i < N; i++) {
if (S[i] == '!') {
if (!flag) return -1;
continue;
}
if (S[i] == 'H') {
sta.push(1);
}
else {
if (sta.empty()) return -1;
else {
sta.pop();
flag = true;
}
}
}
if (!sta.empty()) return -1;
int ret = 0;
int l = 1, r = 1000000, mid;
while (l <= r) {
bool suc = true;
mid = (l + r) / 2;
sp = wp = 0;
bool flag = false;
for (int i = 0; i < N; i++) {
if (S[i] == '!') {
if (!flag && (sta.empty() || sta.top() == -1)) {
suc = false;
break;
}
else if(!sta.empty() && sta.top() > 0){
sta.top()--;
if (sta.top() == 0) sta.pop();
}
}
else if (S[i] == 'H') {
sta.push(-1);
}
else {
if (sta.empty() || sta.top() != -1) {
suc = false;
break;
}
else {
sta.pop();
sta.push(mid);
flag = true;
}
}
}
if (suc && sta.empty()) {
ret = mid;
l = mid + 1;
}
else r = mid - 1;
}
return ret;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |