Submission #613049

# Submission time Handle Problem Language Result Execution time Memory
613049 2022-07-30T03:07:50 Z czhang2718 HicCup (FXCUP4_hiccup) C++17
0 / 100
1 ms 212 KB
#include "hiccup.h"
using namespace std;
#include "bits/stdc++.h"

int HicCup(std::string S) {
	int n = S.size();

	auto check=[&](int x){
		stack<char> s;
		int cur=0;
		for(int i=0; i<n; i++){
			if(S[i]=='!'){
				cur++;
				if(cur==x){
					if(s.size()<2) return 0;
					char c=s.top(); s.pop();
					char h=s.top(); s.pop();
					if(c!='C' || h!='H') return 0;
					cur=0;
				}
				
			}
			if(S[i]=='C'){
				if(cur) return 0;
				s.push('C');
			}
			if(S[i]=='H'){
				if(cur) return 0;
				s.push('H');
			}
		}
		if(s.size()) return 0;
		return 1;
	};

	int x=0;
	for(int i=19; i>=0; i--){
		if(x+(1<<i)<n && check(x+(1<<i))) x+=(1<<i);
	}
	if(!check(x)) return -1;
	return x;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -