답안 #149697

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149697 2019-09-01T06:59:09 Z Welcome to osu!(#3734, easrui, CodePlatina, jhwest2) HicCup (FXCUP4_hiccup) C++17
24 / 100
65 ms 9344 KB
#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++;
            if(numH<numC+1) return -1;
            C[numC] = i;
            L[st.top()] = numC;
            st.pop();
        }
	}
	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 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 8 ms 512 KB Output is correct
5 Correct 65 ms 9336 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 12 ms 3328 KB Output is correct
8 Correct 62 ms 9344 KB Output is correct
9 Correct 62 ms 9208 KB Output is correct
10 Correct 12 ms 3328 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 8 ms 512 KB Output is correct
5 Correct 65 ms 9336 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 12 ms 3328 KB Output is correct
8 Correct 62 ms 9344 KB Output is correct
9 Correct 62 ms 9208 KB Output is correct
10 Correct 12 ms 3328 KB Output is correct
11 Correct 17 ms 4224 KB Output is correct
12 Correct 15 ms 3712 KB Output is correct
13 Correct 13 ms 3328 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 15 ms 3456 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Incorrect 14 ms 3456 KB Output isn't correct
20 Halted 0 ms 0 KB -