Submission #151047

# Submission time Handle Problem Language Result Execution time Memory
151047 2019-09-01T15:37:29 Z dongwon0427 HicCup (FXCUP4_hiccup) C++17
100 / 100
149 ms 43880 KB
#include "hiccup.h"
#include <stack>
#include <vector>

int par[1000005];
int fr[1000005];
int len[1000005];
std::vector<int> child[1000005];

int dfs(int idx) {

    int mn = 1e6;
    int sum = 0;
    for(int i=0;i<child[idx].size();i++) {
        mn = std::min(mn, dfs(child[idx][i]));
    }
    for(int i=0;i<child[idx].size();i++) {
        sum += len[child[idx][i]];
        mn = std::min(mn, sum/(i+1));
    }
    return mn;
}
int HicCup(std::string S) {
	int n = S.size();
	if(S[0] != 'H') return -1;

	std::stack<int> ST;
	ST.push(1);
	for(int i=0;i<n;i++) {
        if(S[i] == 'H') {
            par[i+2] = ST.top();
            ST.push(i+2);
        } else if(S[i] == 'C') {
            if(ST.top() == 1) return -1;
            fr[i] = ST.top();
            ST.pop();
        }
	}
	if(ST.size() != 1) return -1;

	for(int i=0;i<n;i++) {
        if(S[i] == 'C') {
            if(fr[i] == 0) return -1;
        }
	}

	for(int i=0;i<n;i++) {
        if(S[i] == 'C') {
            for(int j=i+1;j<n;j++) {
                if(S[j] != '!') break;
                len[fr[i]]++;
            }
        }
	}

	for(int i=0;i+1<n;i++) {
        if(S[i] == 'H') {
            if(S[i+1] == '!') return -1;
        }
	}

	for(int i=n-1;i>=0;i--) {
        if(S[i] == 'H') {
            child[par[i+2]].push_back(i+2);
        }
	}



	/*for(int i=0;i<n;i++) {
        if(S[i] == 'H') {
            printf("%d %d\n",i+2,len[i+2]);
        }
	}

	for(int i=1;i<=n+2;i++) {
        if(child[i].size()) {
            printf("%d ",i);
            for(int j : child[i]) printf("%d ",j);
            printf("\n");
        }
	}*/
	//HHC!!!HC!C!!!!!!
	return dfs(1);
}

Compilation message

hiccup.cpp: In function 'int dfs(int)':
hiccup.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<child[idx].size();i++) {
                 ~^~~~~~~~~~~~~~~~~~
hiccup.cpp:17:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<child[idx].size();i++) {
                 ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 27 ms 24572 KB Output is correct
5 Correct 143 ms 42616 KB Output is correct
6 Correct 30 ms 26788 KB Output is correct
7 Correct 31 ms 26744 KB Output is correct
8 Correct 149 ms 42772 KB Output is correct
9 Correct 139 ms 42744 KB Output is correct
10 Correct 31 ms 26812 KB Output is correct
11 Correct 23 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 27 ms 24572 KB Output is correct
5 Correct 143 ms 42616 KB Output is correct
6 Correct 30 ms 26788 KB Output is correct
7 Correct 31 ms 26744 KB Output is correct
8 Correct 149 ms 42772 KB Output is correct
9 Correct 139 ms 42744 KB Output is correct
10 Correct 31 ms 26812 KB Output is correct
11 Correct 34 ms 28280 KB Output is correct
12 Correct 35 ms 29564 KB Output is correct
13 Correct 31 ms 27128 KB Output is correct
14 Correct 24 ms 23800 KB Output is correct
15 Correct 45 ms 38552 KB Output is correct
16 Correct 24 ms 23800 KB Output is correct
17 Correct 24 ms 23800 KB Output is correct
18 Correct 24 ms 24092 KB Output is correct
19 Correct 47 ms 38252 KB Output is correct
20 Correct 49 ms 38520 KB Output is correct
21 Correct 41 ms 32760 KB Output is correct
22 Correct 34 ms 27640 KB Output is correct
23 Correct 36 ms 27896 KB Output is correct
24 Correct 52 ms 39640 KB Output is correct
25 Correct 109 ms 43880 KB Output is correct
26 Correct 63 ms 40212 KB Output is correct
27 Correct 41 ms 33784 KB Output is correct
28 Correct 36 ms 28792 KB Output is correct
29 Correct 35 ms 28024 KB Output is correct
30 Correct 29 ms 23800 KB Output is correct
31 Correct 24 ms 23800 KB Output is correct
32 Correct 25 ms 24440 KB Output is correct
33 Correct 23 ms 23800 KB Output is correct