# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
151523 | leduykhongngu | HicCup (FXCUP4_hiccup) | C++17 | 12 ms | 632 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
string S = "";
int n;
bool Check(int x)
{
stack<char> st;
stack<int> cnt;
int cur = 0; bool chk = true;
for (int i = 0; i < n; ++i)
{
// cout << S[i] << ' ' << cur << endl;
if (S[i] != '!')
{
st.push(S[i]);
if(cur) cnt.push(cur);
cur = 0;
}
else
{
if (chk) return false;
if (st.size() && st.top() != 'H')
{
++cur;
st.push(S[i]);
}
}
if (cur == x)
{
for (int i = 1; i <= x; ++i)
if (st.top() == '!') st.pop();
else return false;
while (st.size() && st.top() == '!')
st.pop();
if (st.size() && st.top() == 'C') st.pop();
else return false;
if (st.size() && st.top() == 'H') st.pop();
else return false;
if (cnt.empty()) cur = 0;
else
{
cur = cnt.top();
cnt.pop();
}
}
chk = !((S[i] == 'C') || (S[i] == '!'));
}
return st.empty();
}
int HicCup(std::string tmp)
{
for (int i = 0; i < tmp.length(); ++i)
{
S.push_back(tmp[i]);
if (tmp[i] == 'C') S.push_back('!');
}
n = S.length();
// cout << Check(1);
int lef = 0, rig = n, ans = -1;
while (lef <= rig)
{
int mid = lef + rig >> 1;
if (Check(mid))
{
ans = max(ans, mid);
lef = mid + 1;
}
else rig = mid - 1;
}
if (ans != -1) --ans;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |