#include <bits/stdc++.h>
#include "hiccup.h"
using namespace std;
const int MN = 1e6+5;
int H[MN],C[MN],L[MN];
int numH,numC=-1;
stack<int> st;
int proc(int s, int e, int d)
{
int res = MN, cnt, num;
if(e-s+d==0){
if(H[s]+1!=C[e]) return -1;
else return MN;
}
if(H[s+1]!=H[s]+1) return -1;
int s0 = s+1, e0 = L[s0];
priority_queue<int, vector<int>, greater<int> > PQ;
while(s0<=e+d){
res = min(res,proc(s0,e0,d+1));
if(e0+2>e){
cnt = C[e]-C[e0]-1;
//if(s==0) cout << cnt << '\n';
break;
}
//if(s==0) cout << H[e0+d+2]-C[e0]-1 << '\n';
PQ.push(H[e0+d+2]-C[e0]-1);
s0 = e0+d+2, e0 = L[s0];
}
PQ.push(0);
while(cnt){
num = PQ.top();
PQ.pop();
PQ.push(num+1);
cnt--;
}
res = min(res,PQ.top());
//cout << s << ' ' << e << ' ' << d << ' ' << res << '\n';
return res;
}
int HicCup(std::string S) {
int N = S.size();
for(int i=0; i<N; i++){
if(S[i]=='!') continue;
if(S[i]=='H'){
numH++;
st.push(numH);
H[numH] = i;
}
if(S[i]=='C'){
numC++;
C[numC] = i;
L[st.top()] = numC;
st.pop();
}
if(numH<numC+1) return -1;
}
if(numH!=numC+1) return -1;
H[0] = -1;
L[0] = numH;
C[numH] = N;
return proc(0,numH,0);
}
Compilation message
hiccup.cpp: In function 'int proc(int, int, int)':
hiccup.cpp:35:12: warning: 'cnt' may be used uninitialized in this function [-Wmaybe-uninitialized]
cnt--;
~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Runtime error |
6 ms |
560 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Runtime error |
6 ms |
560 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |