Submission #150501

# Submission time Handle Problem Language Result Execution time Memory
150501 2019-09-01T08:31:59 Z 오리버스부릉부릉(#3679, rdd6584, orihehe, phpark) HicCup (FXCUP4_hiccup) C++17
24 / 100
36 ms 7536 KB
#include "hiccup.h"
#include <stack>
#include <vector>
using namespace std;

vector<int> ss, ww;
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;
			ww.push_back(i);
			continue;
		}
		if (S[i] == 'H') {
			sta.push(1);
		}
		else {
			if (sta.empty()) return -1;
			else {
				sta.pop();
				ss.push_back(i);
				flag = true;
			}
		}
	}
	if (!sta.empty()) return -1;

	int ret = 0;
	int l = 1, r = 1000000, mid;
	int sz = ss.size(), wz = ww.size();
	while (l <= r) {
		bool suc = true;
		mid = (l + r) / 2;
		sp = wp = 0;
		for (int v : ss) {
			while (wp < wz && ww[wp] < v) wp++;
			if (wp == wz) {
				suc = false; break;
			}
			int cnt = 0;
			while (wp < wz && cnt < mid) {
				cnt++;
				wp++;
			}
			if (cnt < mid) {
				suc = false; break;
			}
		}
		if (suc) {
			ret = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	return ret;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:10:6: warning: variable 'sp' set but not used [-Wunused-but-set-variable]
  int sp, wp;
      ^~
hiccup.cpp:34:6: warning: unused variable 'sz' [-Wunused-variable]
  int sz = ss.size(), wz = ww.size();
      ^~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 128 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 25 ms 5492 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 14 ms 3328 KB Output is correct
8 Correct 25 ms 5364 KB Output is correct
9 Correct 28 ms 5364 KB Output is correct
10 Correct 13 ms 3200 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 128 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 25 ms 5492 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 14 ms 3328 KB Output is correct
8 Correct 25 ms 5364 KB Output is correct
9 Correct 28 ms 5364 KB Output is correct
10 Correct 13 ms 3200 KB Output is correct
11 Correct 16 ms 4136 KB Output is correct
12 Correct 19 ms 5620 KB Output is correct
13 Correct 16 ms 3964 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Incorrect 36 ms 7536 KB Output isn't correct
16 Halted 0 ms 0 KB -