Submission #149905

# Submission time Handle Problem Language Result Execution time Memory
149905 2019-09-01T07:22:39 Z =SUM(D1:D9)(#3629, ydk1104, stet_stet, Hyperbolic) HicCup (FXCUP4_hiccup) C++17
24 / 100
29 ms 5492 KB
#include<vector>
#include<algorithm>
#include "hiccup.h"

int HicCup(std::string S) {
	int N = S.size();
	int stack = 0;
	int mark = 0;
	std::vector<int> v;
	for(auto i:S){
		if(i == '!') mark++;
	}
	int left=0, right=mark, prev = 'H';
	for(int i=0; i<N; i++){
		if(S[i] == 'H') stack++;
		if(S[i] == 'C'){
			stack--;
			if(stack < 0) return -1;
			v.push_back(mark);
		}
		if(S[i] == '!') mark--;
		if(S[i] == '!' && prev == 'H') return -1;
		prev = S[i];
	}
	while(left < right){
		int mid = (left+right)/2;
		int prev = v[0];
		for(auto i:v){
			prev = std::min(prev, i) - mid;
		}
		if(prev < 0) right = mid-1;
		left = mid+1;
	}
	int ans = 0;
	for(int mid=left-3; mid <= left+3; mid++){
		int prev = v[0];
		for(auto i:v){
			prev = std::min(prev, i) - mid;
		}
		if(prev < 0) break;
		ans = mid;
	}
	if(stack) return -1;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 29 ms 5492 KB Output is correct
6 Correct 15 ms 3328 KB Output is correct
7 Correct 15 ms 3328 KB Output is correct
8 Correct 29 ms 5492 KB Output is correct
9 Correct 28 ms 5492 KB Output is correct
10 Correct 15 ms 3328 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 29 ms 5492 KB Output is correct
6 Correct 15 ms 3328 KB Output is correct
7 Correct 15 ms 3328 KB Output is correct
8 Correct 29 ms 5492 KB Output is correct
9 Correct 28 ms 5492 KB Output is correct
10 Correct 15 ms 3328 KB Output is correct
11 Correct 19 ms 3964 KB Output is correct
12 Correct 17 ms 3584 KB Output is correct
13 Correct 15 ms 3328 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 15 ms 3376 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Incorrect 17 ms 3328 KB Output isn't correct
20 Halted 0 ms 0 KB -