Submission #149322

# Submission time Handle Problem Language Result Execution time Memory
149322 2019-09-01T06:14:49 Z koosaga fan club(#3590, xiaowuc1) HicCup (FXCUP4_hiccup) C++17
100 / 100
119 ms 4372 KB
#include <bits/stdc++.h>
#include "hiccup.h"

using namespace std;

const int HONLY = -1;
const int HCONLY = 0;
bool valid(string s, int sz) {
	vector<int> v;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'H') {
			if(v.size() && v.back() >= sz) v.pop_back();
			v.push_back(HONLY);
			continue;
		}
		if(s[i] == 'C') {
			if(v.size() && v.back() >= sz) v.pop_back();
			if(v.empty()) return false;
			if(v.back() != HONLY) return false;
			v.pop_back();
			v.push_back(HCONLY);
			continue;
		}
		assert(s[i] == '!');
		if(v.empty() || v.back() < 0) return false;
		v[v.size()-1]++;
		if(v.back() == sz && v.size() >= 2 && v[v.size()-2] >= 0) v.pop_back();
	}
	while(v.size() && v.back() >= sz) v.pop_back();
	return v.empty();
}

int HicCup(std::string S) {
	int lhs = -1;
	int rhs = S.size();
	while(lhs != rhs) {
		int mid = (lhs+rhs+1)/2;
		if(valid(S, mid)) lhs = mid;
		else rhs = mid-1;
	}
	return lhs;
}

Compilation message

hiccup.cpp: In function 'bool valid(std::__cxx11::string, int)':
hiccup.cpp:10:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < s.size(); i++) {
                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 24 ms 4268 KB Output is correct
6 Correct 15 ms 4268 KB Output is correct
7 Correct 16 ms 4352 KB Output is correct
8 Correct 25 ms 4352 KB Output is correct
9 Correct 26 ms 4268 KB Output is correct
10 Correct 15 ms 4352 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 24 ms 4268 KB Output is correct
6 Correct 15 ms 4268 KB Output is correct
7 Correct 16 ms 4352 KB Output is correct
8 Correct 25 ms 4352 KB Output is correct
9 Correct 26 ms 4268 KB Output is correct
10 Correct 15 ms 4352 KB Output is correct
11 Correct 20 ms 4352 KB Output is correct
12 Correct 20 ms 4352 KB Output is correct
13 Correct 24 ms 4140 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 24 ms 4352 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
19 Correct 55 ms 4268 KB Output is correct
20 Correct 35 ms 4140 KB Output is correct
21 Correct 86 ms 4224 KB Output is correct
22 Correct 81 ms 4164 KB Output is correct
23 Correct 119 ms 4352 KB Output is correct
24 Correct 31 ms 4268 KB Output is correct
25 Correct 24 ms 4352 KB Output is correct
26 Correct 29 ms 4352 KB Output is correct
27 Correct 104 ms 4372 KB Output is correct
28 Correct 117 ms 4224 KB Output is correct
29 Correct 118 ms 4352 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 12 ms 640 KB Output is correct
33 Correct 5 ms 384 KB Output is correct