Submission #151837

# Submission time Handle Problem Language Result Execution time Memory
151837 2019-09-05T04:52:38 Z tmwilliamlin168 HicCup (FXCUP4_hiccup) C++17
100 / 100
28 ms 8188 KB
#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;

int a[1000000], lb=0, rb=1000000, mb;

bool chk(string &s, int l, int r, int b=0) {
	if(l>r)
		return 1;
	for(; s[r]=='!'; --r, ++b);
	return b<mb?0:chk(s, a[r]+1, r-1)&&chk(s, l, a[r]-1, b-mb);
}

int HicCup(string s) {
	int n=s.size();
	if(s[0]=='!')
		return -1;
	for(int i=0; i+1<n; ++i)
		if(s[i]=='H'&&s[i+1]=='!')
			return -1;
	vector<int> t;
	for(int i=0; i<n; ++i) {
		if(s[i]=='C') {
			if(t.empty())
				return -1;
			a[i]=t.back();
			t.pop_back();
		} else if(s[i]=='H')
			t.push_back(i);
	}
	if(t.size())
		return -1;
	while(lb<rb) {
		mb=(lb+rb+1)/2;
		if(chk(s, 0, n-1))
			lb=mb;
		else
			rb=mb-1;
	}
	return lb;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 28 ms 8180 KB Output is correct
6 Correct 15 ms 4220 KB Output is correct
7 Correct 15 ms 4216 KB Output is correct
8 Correct 28 ms 8188 KB Output is correct
9 Correct 28 ms 8184 KB Output is correct
10 Correct 15 ms 4216 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 28 ms 8180 KB Output is correct
6 Correct 15 ms 4220 KB Output is correct
7 Correct 15 ms 4216 KB Output is correct
8 Correct 28 ms 8188 KB Output is correct
9 Correct 28 ms 8184 KB Output is correct
10 Correct 15 ms 4216 KB Output is correct
11 Correct 14 ms 4216 KB Output is correct
12 Correct 11 ms 4216 KB Output is correct
13 Correct 9 ms 4216 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 9 ms 4216 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 18 ms 8056 KB Output is correct
20 Correct 19 ms 8184 KB Output is correct
21 Correct 22 ms 6020 KB Output is correct
22 Correct 18 ms 4088 KB Output is correct
23 Correct 27 ms 4216 KB Output is correct
24 Correct 18 ms 8184 KB Output is correct
25 Correct 26 ms 8184 KB Output is correct
26 Correct 21 ms 8184 KB Output is correct
27 Correct 18 ms 6264 KB Output is correct
28 Correct 20 ms 4600 KB Output is correct
29 Correct 24 ms 4216 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 2 ms 380 KB Output is correct