Submission #150397

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

vector<int> ss, ww;
int HicCup(std::string S) {
	int N = S.size();
	int sp, wp;
	stack<int> sta;
	for (int i = 0; i < N; i++) {
		if (S[i] == '!') {
			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);
			}
		}
	}
	if (!sta.empty()) return -1;

	int ret = 0;
	int l = 0, 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 || ww[wp] < v) {
				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:9:6: warning: variable 'sp' set but not used [-Wunused-but-set-variable]
  int sp, wp;
      ^~
hiccup.cpp:31:6: warning: unused variable 'sz' [-Wunused-variable]
  int sz = ss.size(), wz = ww.size();
      ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 128 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 26 ms 5484 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 25 ms 5492 KB Output is correct
9 Correct 26 ms 5492 KB Output is correct
10 Correct 13 ms 3160 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 128 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 26 ms 5484 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 25 ms 5492 KB Output is correct
9 Correct 26 ms 5492 KB Output is correct
10 Correct 13 ms 3160 KB Output is correct
11 Correct 15 ms 4136 KB Output is correct
12 Correct 17 ms 5620 KB Output is correct
13 Correct 14 ms 3836 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Incorrect 34 ms 7536 KB Output isn't correct
16 Halted 0 ms 0 KB -