// #include "hiccup.h"
using namespace std;
#include "bits/stdc++.h"
const int N=1e6+1;
vector<int> adj[N];
int cnt[N];
int ans;
bool bad;
void dfs(int x){
int e=0, c=0;
for(int i=adj[x].size()-1; i>=0; i--){
int k=adj[x][i];
e+=cnt[k];
c++;
ans=min(ans, e/c);
dfs(k);
}
}
int HicCup(std::string S) {
int n = S.size();
ans=1e9;
S='-'+S;
stack<int> par;
par.push(0);
int prv=-1;
for(int i=1; i<=n; i++){
if(S[i]=='!'){
if(prv==-1 || S[i-1]=='H') return -1;
cnt[prv]++;
continue;
}
if(S[i]=='C'){
if(par.size()<2) return -1;
int p=par.top(); par.pop();
prv=p;
adj[par.top()].push_back(p);
}
else{
par.push(i);
}
}
// for(int i=0; i<=n; i++){
// if(cnt[i]) cout << "cnt[" << i << "] " << cnt[i] << "\n";
// }
if(par.size()!=1) return -1;
dfs(0);
return ans;
}
// int main(){
// string s;
// cin >> s;
// cout << HicCup(s);
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
15 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23804 KB |
Output is correct |
4 |
Correct |
14 ms |
24212 KB |
Output is correct |
5 |
Correct |
57 ms |
34760 KB |
Output is correct |
6 |
Correct |
21 ms |
27708 KB |
Output is correct |
7 |
Correct |
21 ms |
27720 KB |
Output is correct |
8 |
Correct |
57 ms |
34836 KB |
Output is correct |
9 |
Correct |
58 ms |
34808 KB |
Output is correct |
10 |
Correct |
17 ms |
27604 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
15 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23804 KB |
Output is correct |
4 |
Correct |
14 ms |
24212 KB |
Output is correct |
5 |
Correct |
57 ms |
34760 KB |
Output is correct |
6 |
Correct |
21 ms |
27708 KB |
Output is correct |
7 |
Correct |
21 ms |
27720 KB |
Output is correct |
8 |
Correct |
57 ms |
34836 KB |
Output is correct |
9 |
Correct |
58 ms |
34808 KB |
Output is correct |
10 |
Correct |
17 ms |
27604 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
23 ms |
28304 KB |
Output is correct |
13 |
Correct |
20 ms |
28416 KB |
Output is correct |
14 |
Correct |
19 ms |
27708 KB |
Output is correct |
15 |
Correct |
14 ms |
23692 KB |
Output is correct |
16 |
Correct |
19 ms |
27636 KB |
Output is correct |
17 |
Correct |
13 ms |
23764 KB |
Output is correct |
18 |
Correct |
14 ms |
23764 KB |
Output is correct |
19 |
Correct |
13 ms |
24148 KB |
Output is correct |
20 |
Correct |
22 ms |
30592 KB |
Output is correct |
21 |
Correct |
27 ms |
30708 KB |
Output is correct |
22 |
Correct |
22 ms |
29332 KB |
Output is correct |
23 |
Correct |
21 ms |
28368 KB |
Output is correct |
24 |
Correct |
22 ms |
28600 KB |
Output is correct |
25 |
Correct |
22 ms |
31780 KB |
Output is correct |
26 |
Correct |
47 ms |
35940 KB |
Output is correct |
27 |
Correct |
28 ms |
32384 KB |
Output is correct |
28 |
Correct |
21 ms |
29712 KB |
Output is correct |
29 |
Correct |
22 ms |
28520 KB |
Output is correct |
30 |
Correct |
21 ms |
28648 KB |
Output is correct |
31 |
Correct |
12 ms |
23708 KB |
Output is correct |
32 |
Correct |
13 ms |
23892 KB |
Output is correct |
33 |
Correct |
13 ms |
24140 KB |
Output is correct |