Submission #149910

# Submission time Handle Problem Language Result Execution time Memory
149910 2019-09-01T07:22:50 Z 강한친구 대한육군(#3592, pichulia) HicCup (FXCUP4_hiccup) C++17
100 / 100
59 ms 28928 KB
#include "hiccup.h"
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v[1000009];
int HicCup(std::string a) {
	int n = a.size();
	int i, j, k;
	for (i = j=k=0; i < n; i++) {
		if (a[i] == 'H') {
			k++; j = 0;
		}
		else if (a[i] == 'C') { k--; j = 1; if (k < 0)return -1; }
		else {
			if (j == 0)return -1;
		}
	}
	if (k > 0) return -1;
	int l = 1;
	int r = n;
	std::string b = a;
	b.resize(n + 1);
	b[n] = 'X';

	int res = n;

	int st = 0;
	for (i = 0; i < n; i++) {
		//printf("%d %d\n", i, st);
		if(a[i] == 'H'){
			v[st].push_back(0);
			st++;
		}
		else if (a[i] == 'C')
		{
			if (v[st].size() > 0)
			{
				int sum = 0;
				int cnt = 0;
				for (j = v[st].size() - 1; j >= 0; j--)
				{
					sum += v[st][j];
					cnt++;
					res = min(res, sum / cnt);
				}
			}
			v[st].clear();

			st--;
		}
		else {
			v[st][v[st].size() - 1]++;
		}
	}
	if (v[st].size() > 0)
	{
		int sum = 0;
		int cnt = 0;
		for (j = v[st].size() - 1; j >= 0; j--)
		{
			sum += v[st][j];
			cnt++;
			res = min(res, sum / cnt);
		}
	}
	v[st].clear();

	return res;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:19:6: warning: unused variable 'l' [-Wunused-variable]
  int l = 1;
      ^
hiccup.cpp:20:6: warning: unused variable 'r' [-Wunused-variable]
  int r = n;
      ^
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 19 ms 23808 KB Output is correct
3 Correct 20 ms 23808 KB Output is correct
4 Correct 22 ms 24064 KB Output is correct
5 Correct 59 ms 28800 KB Output is correct
6 Correct 29 ms 26752 KB Output is correct
7 Correct 27 ms 26744 KB Output is correct
8 Correct 47 ms 28664 KB Output is correct
9 Correct 46 ms 28716 KB Output is correct
10 Correct 28 ms 26752 KB Output is correct
11 Correct 20 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 19 ms 23808 KB Output is correct
3 Correct 20 ms 23808 KB Output is correct
4 Correct 22 ms 24064 KB Output is correct
5 Correct 59 ms 28800 KB Output is correct
6 Correct 29 ms 26752 KB Output is correct
7 Correct 27 ms 26744 KB Output is correct
8 Correct 47 ms 28664 KB Output is correct
9 Correct 46 ms 28716 KB Output is correct
10 Correct 28 ms 26752 KB Output is correct
11 Correct 29 ms 26752 KB Output is correct
12 Correct 28 ms 26752 KB Output is correct
13 Correct 28 ms 26752 KB Output is correct
14 Correct 20 ms 23808 KB Output is correct
15 Correct 28 ms 26752 KB Output is correct
16 Correct 18 ms 23808 KB Output is correct
17 Correct 30 ms 23808 KB Output is correct
18 Correct 19 ms 24088 KB Output is correct
19 Correct 35 ms 28672 KB Output is correct
20 Correct 33 ms 28792 KB Output is correct
21 Correct 33 ms 28800 KB Output is correct
22 Correct 32 ms 28416 KB Output is correct
23 Correct 37 ms 28792 KB Output is correct
24 Correct 35 ms 28784 KB Output is correct
25 Correct 48 ms 28744 KB Output is correct
26 Correct 36 ms 28664 KB Output is correct
27 Correct 34 ms 28928 KB Output is correct
28 Correct 35 ms 28544 KB Output is correct
29 Correct 35 ms 28764 KB Output is correct
30 Correct 20 ms 23808 KB Output is correct
31 Correct 19 ms 23808 KB Output is correct
32 Correct 21 ms 24192 KB Output is correct
33 Correct 20 ms 23808 KB Output is correct