Submission #149522

# Submission time Handle Problem Language Result Execution time Memory
149522 2019-09-01T06:40:32 Z From The Sky(#3630, WhipppedCream, top34051, zoomswk) HicCup (FXCUP4_hiccup) C++17
0 / 100
1000 ms 262144 KB
#include "hiccup.h"
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
using namespace std;

int HicCup(std::string S) {
	int N = S.size();
	stack<int> st[N+2];
	int mask = 0;
	int bal = 0;
	for(int i=0; i<N; i++){
		if(S[i] == '!' && mask != 3) return -1;
		if(S[i] == 'H') bal++, mask |= 1;
		if(S[i] == 'C') bal--, mask |= 2;
		if(bal < 0) return -1;
	}
	if(bal > 0) return -1;
	int l=1, r=N, res=0;
	while(l<=r){
		int mid=(l+r)/2;
		int ok = 1;
		int level = 0;
		while(!st[0].empty()) st[0].pop();
		for(int i=0; i<N; i++){
			if(S[i] == 'H'){
				level++;
				while(!st[level].empty()) st[level].pop();
			} else if(S[i] == 'C'){
				if(st[level].size()){
					ok = 0;
					break;
				}
				level--;
				st[level].push(0);
			} else{
				if(level == -1) return -1;
				if(st[level].size()){
					int x = st[level].top();
					x++;
					st[level].pop();
					if(x != mid){
						st[level].push(x);
					}
				}
			}
		}
		if(st[0].empty() && ok) res = mid, l = mid+1;
		else r = mid-1;
	}
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 7 ms 1536 KB Output is correct
4 Correct 28 ms 25856 KB Output is correct
5 Execution timed out 1024 ms 262144 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 7 ms 1536 KB Output is correct
4 Correct 28 ms 25856 KB Output is correct
5 Execution timed out 1024 ms 262144 KB Time limit exceeded
6 Halted 0 ms 0 KB -