답안 #149487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149487 2019-09-01T06:35:46 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();
	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;
		stack<int> st[N+1];
		int level = 0;
		for(int i=0; i<N; i++){
			if(S[i] == 'H'){
				level++;
			} 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 117 ms 25856 KB Output is correct
5 Execution timed out 1032 ms 262144 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 117 ms 25856 KB Output is correct
5 Execution timed out 1032 ms 262144 KB Time limit exceeded
6 Halted 0 ms 0 KB -