Submission #150677

# Submission time Handle Problem Language Result Execution time Memory
150677 2019-09-01T08:48:45 Z =SUM(D1:D9)(#3629, ydk1104, stet_stet, Hyperbolic) HicCup (FXCUP4_hiccup) C++17
24 / 100
28 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;
		if(S[0]=='!') 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 5 ms 384 KB Output is correct
2 Correct 5 ms 128 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 28 ms 5492 KB Output is correct
6 Correct 15 ms 3328 KB Output is correct
7 Correct 14 ms 3328 KB Output is correct
8 Correct 28 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 128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 128 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 28 ms 5492 KB Output is correct
6 Correct 15 ms 3328 KB Output is correct
7 Correct 14 ms 3328 KB Output is correct
8 Correct 28 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 3956 KB Output is correct
12 Correct 18 ms 3584 KB Output is correct
13 Correct 14 ms 3328 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 15 ms 3328 KB Output is correct
16 Correct 5 ms 128 KB Output is correct
17 Correct 5 ms 128 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Incorrect 17 ms 3200 KB Output isn't correct
20 Halted 0 ms 0 KB -