#include "hiccup.h"
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
vector<int> v;
int hc[1000001];
string ss;
int ans = 1e9;
void dnc(int l, int r) {
int cnt = 0, nf = 0, cc = 0;
for (int i = r; i >= l; i--) {
if (ss[i] == '!') {
cnt++;
nf = 1;
}
else {
dnc(hc[i] + 1, i - 1);
i = hc[i];
cc++;
ans = min(ans, cnt / cc);
nf = 0;
}
}
if (nf) ans = -1;
}
int HicCup(std::string s) {
int n = s.size();
ss = s;
for (int i = 0; i < n; i++) {
if (s[i] == 'H')
v.push_back(i);
else if (s[i] == 'C') {
if (v.empty()) return -1;
hc[i] = v.back();
v.pop_back();
}
}
if (!v.empty()) return -1;
dnc(0, n - 1);
// 가장 외곽 괄호쌍에서만 느낌표를 받을 수 있다.
// C가 없는 것에 대한 예외처리 필요.
// MIN..
// 안쪽에 대해서만.
//
// 그 괄호로 둘러쌓여져 있는 부분에서.
//
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
632 KB |
Output is correct |
5 |
Correct |
29 ms |
8824 KB |
Output is correct |
6 |
Correct |
10 ms |
4856 KB |
Output is correct |
7 |
Correct |
10 ms |
4856 KB |
Output is correct |
8 |
Correct |
30 ms |
8696 KB |
Output is correct |
9 |
Correct |
30 ms |
8696 KB |
Output is correct |
10 |
Correct |
10 ms |
4728 KB |
Output is correct |
11 |
Correct |
2 ms |
276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
632 KB |
Output is correct |
5 |
Correct |
29 ms |
8824 KB |
Output is correct |
6 |
Correct |
10 ms |
4856 KB |
Output is correct |
7 |
Correct |
10 ms |
4856 KB |
Output is correct |
8 |
Correct |
30 ms |
8696 KB |
Output is correct |
9 |
Correct |
30 ms |
8696 KB |
Output is correct |
10 |
Correct |
10 ms |
4728 KB |
Output is correct |
11 |
Correct |
12 ms |
5624 KB |
Output is correct |
12 |
Correct |
12 ms |
6136 KB |
Output is correct |
13 |
Correct |
10 ms |
4984 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
17 ms |
8696 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
3 ms |
760 KB |
Output is correct |
19 |
Correct |
17 ms |
8696 KB |
Output is correct |
20 |
Correct |
17 ms |
8696 KB |
Output is correct |
21 |
Correct |
15 ms |
6520 KB |
Output is correct |
22 |
Correct |
13 ms |
4728 KB |
Output is correct |
23 |
Correct |
13 ms |
4984 KB |
Output is correct |
24 |
Correct |
17 ms |
8824 KB |
Output is correct |
25 |
Correct |
29 ms |
8824 KB |
Output is correct |
26 |
Correct |
20 ms |
8824 KB |
Output is correct |
27 |
Correct |
15 ms |
7032 KB |
Output is correct |
28 |
Correct |
13 ms |
5240 KB |
Output is correct |
29 |
Correct |
13 ms |
4984 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
3 ms |
760 KB |
Output is correct |
33 |
Correct |
2 ms |
276 KB |
Output is correct |