답안 #150710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150710 2019-09-01T08:50:59 Z GucciBelt(#3697, PeppaPig, win11905, DodgeBallMan) HicCup (FXCUP4_hiccup) C++17
100 / 100
85 ms 8192 KB
#include "hiccup.h"
#define pii pair<int, int>
#define x first
#define y second
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6+5;

int n, lvl[N];
string str;

bool checkFunction(int mid) {
	int  cnt = 0;
	stack<pii> stk;
	for(int i = 0; i < n; ++i) {
		if(str[i] == 'C') {
			cnt--;
			if(!stk.empty() && stk.top().y > cnt) return false;
			stk.emplace(0, cnt);
		}
		if(str[i] == '!') {
			if(stk.empty()) continue;
			pii now = stk.top(); stk.pop();
			if(++now.x == mid) continue;
			stk.emplace(now);
		} 
		if(str[i] == 'H') {
			cnt++;
		}
	}
	return stk.empty();
}

int HicCup(string S) {
	str = S;
	n = S.size();
	int cnt = 0, pv = -1;
	for(int i = 0; i < n; ++i) {
		if(S[i] == 'H') cnt++, pv = -1;
		if(S[i] == 'C') {
			lvl[i] = cnt;
			if(!~--cnt) return -1;
			else pv = i;
		}
		if(S[i] == '!') {
			if(pv == -1) return -1;	
			else lvl[i] = lvl[pv];
		}
	}
	if(cnt) return -1;
	int l = 0, r = S.size();
	while(l < r) {
		int mid = (l + r + 1) >> 1;
		if(checkFunction(mid)) l = mid;
		else r = mid-1;
	}	
	return l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 336 KB Output is correct
3 Correct 6 ms 380 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 22 ms 8192 KB Output is correct
6 Correct 16 ms 4352 KB Output is correct
7 Correct 14 ms 4224 KB Output is correct
8 Correct 23 ms 8192 KB Output is correct
9 Correct 24 ms 8192 KB Output is correct
10 Correct 13 ms 4224 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 336 KB Output is correct
3 Correct 6 ms 380 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 22 ms 8192 KB Output is correct
6 Correct 16 ms 4352 KB Output is correct
7 Correct 14 ms 4224 KB Output is correct
8 Correct 23 ms 8192 KB Output is correct
9 Correct 24 ms 8192 KB Output is correct
10 Correct 13 ms 4224 KB Output is correct
11 Correct 17 ms 5120 KB Output is correct
12 Correct 16 ms 5760 KB Output is correct
13 Correct 14 ms 4480 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 15 ms 4312 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 13 ms 768 KB Output is correct
19 Correct 36 ms 8192 KB Output is correct
20 Correct 25 ms 8192 KB Output is correct
21 Correct 65 ms 8192 KB Output is correct
22 Correct 57 ms 7808 KB Output is correct
23 Correct 84 ms 8064 KB Output is correct
24 Correct 22 ms 8192 KB Output is correct
25 Correct 22 ms 8192 KB Output is correct
26 Correct 24 ms 8192 KB Output is correct
27 Correct 71 ms 8192 KB Output is correct
28 Correct 84 ms 8064 KB Output is correct
29 Correct 85 ms 8192 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 11 ms 852 KB Output is correct
33 Correct 6 ms 384 KB Output is correct