답안 #150786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150786 2019-09-01T08:55:53 Z 오리버스부릉부릉(#3679, rdd6584, orihehe, phpark) HicCup (FXCUP4_hiccup) C++17
24 / 100
24 ms 3328 KB
#include "hiccup.h"
#include <stack>
#include <vector>
using namespace std;

int HicCup(std::string S) {
	bool flag = false;
	int N = S.size();
	int sp, wp;
	stack<int> sta;
	for (int i = 0; i < N; i++) {
		if (S[i] == '!') {
			if (!flag) return -1;
			continue;
		}
		if (S[i] == 'H') {
			sta.push(1);
		}
		else {
			if (sta.empty()) return -1;
			else {
				sta.pop();
				flag = true;
			}
		}
	}
	if (!sta.empty()) return -1;

	int ret = 0;
	int l = 1, r = 1000000, mid;
	while (l <= r) {
		bool suc = true;
		mid = (l + r) / 2;
		sp = wp = 0;
		bool flag = false;
		for (int i = 0; i < N; i++) {
			if (S[i] == '!') {
				if (!flag && (sta.empty() || sta.top() == -1)) {
					suc = false;
					break;
				}
				else if(!sta.empty() && sta.top() > 0){
					sta.top()--;
					if (sta.top() == 0) sta.pop();
				}
			}
			else if (S[i] == 'H') {
				sta.push(-1);
			}
			else {
				if (sta.empty() || sta.top() != -1) {
					suc = false;
					break;
				}
				else {
					sta.pop();
					sta.push(mid);
					flag = true;
				}
			}
		}
		
		if (suc && sta.empty()) {
			ret = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	return ret;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:9:6: warning: variable 'sp' set but not used [-Wunused-but-set-variable]
  int sp, wp;
      ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 23 ms 3328 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 23 ms 3328 KB Output is correct
9 Correct 23 ms 3328 KB Output is correct
10 Correct 13 ms 3328 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 23 ms 3328 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 23 ms 3328 KB Output is correct
9 Correct 23 ms 3328 KB Output is correct
10 Correct 13 ms 3328 KB Output is correct
11 Correct 15 ms 3328 KB Output is correct
12 Correct 15 ms 3328 KB Output is correct
13 Correct 13 ms 3328 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Incorrect 24 ms 3328 KB Output isn't correct
16 Halted 0 ms 0 KB -