Submission #148572

# Submission time Handle Problem Language Result Execution time Memory
148572 2019-09-01T04:41:15 Z 강력한 한방 필살기(#3595, gs14004, kriii, OnionPringles) HicCup (FXCUP4_hiccup) C++17
100 / 100
457 ms 19436 KB
#include "hiccup.h"
#include <vector>
using namespace std;

int HicCup(std::string S) {
	int N = S.size();
	int l = -1, r = N;
	while (l + 1 < r){
		int m = (l + r) / 2;

		vector<pair<char, int> > u;
		bool good = true;
		for (int i = 0; i < N; i++){
			if (S[i] == 'H'){
				u.push_back({ S[i],1 });
			}
			else if (S[i] == 'C'){
				if (!u.empty() && u.back().first == 0) u.pop_back();
				u.push_back({ S[i],1 });
			}
			else{
				if (!u.empty() && u.back().first == '!'){
					u.back().second++;
				}
				else if (!u.empty() && u.back().first == 0){
					u.back().second++;
				}
				else{
					u.push_back({ '!',1 });
				}
			}

			while (1){
				int z = u.size();
				if (m == 0){
					if (z >= 2 && u[z - 2].first == 'H' && u[z - 1].first == 'C'){
						u.pop_back();
						u.pop_back();
						if (!u.empty() && u.back().first == 0);
						else u.push_back({ 0,0 });
					}
					else break;
				}
				else{
					if (z >= 3 && u[z - 3].first == 'H' && u[z - 2].first == 'C' && u[z - 1].first == '!' && u[z - 1].second >= m){
						u.pop_back();
						u.pop_back();
						u.pop_back();
						if (!u.empty() && u.back().first == 0);
						else u.push_back({ 0,0 });
					}
					else if (z >= 3 && u[z - 3].first == 'H' && u[z - 2].first == 'C' && u[z - 1].first == 0 && u[z - 1].second >= m){
						u.pop_back();
						u.pop_back();
						u.pop_back();
						if (!u.empty() && u.back().first == 0);
						else u.push_back({ 0,0 });
					}
					else if (z >= 4 && u[z - 4].first == 'H' && u[z - 3].first == 'C' && u[z - 2].first == 0 && u[z - 1].first == '!' && u[z - 2].second + u[z - 1].second >= m){
						int r = u[z - 2].second + u[z - 1].second - m;
						u.pop_back();
						u.pop_back();
						u.pop_back();
						u.pop_back();
						if (!u.empty() && u.back().second == 0) u.back().second += r;
						else u.push_back({ 0,r });
					}
					else if (z >= 4 && u[z - 4].first == 'H' && u[z - 3].first == 'C' && u[z - 2].first == '!' && u[z - 1].first == 0 && u[z - 2].second + u[z - 1].second >= m){
						int r = u[z - 2].second + u[z - 1].second - m;
						u.pop_back();
						u.pop_back();
						u.pop_back();
						u.pop_back();
						if (!u.empty() && u.back().second == 0) u.back().second += r;
						else u.push_back({ 0,r });
					}
					else break;
				}

				while (u.size() >= 2){
					z = u.size();
					if (u[z - 2].first == 0 && (u[z - 1].first == '!' || u[z - 1].first == 0)){
						u[z - 2].second += u[z - 1].second;
						u.pop_back();
					}
					else break;
				}
			}
		}

		while (!u.empty() && u.back().first == 0) u.pop_back();
		if (!u.empty()) good = false;

		if (good) l = m;
		else r = m;
	}
	return l;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 18 ms 1360 KB Output is correct
5 Correct 430 ms 19424 KB Output is correct
6 Correct 408 ms 19432 KB Output is correct
7 Correct 421 ms 19408 KB Output is correct
8 Correct 454 ms 19376 KB Output is correct
9 Correct 457 ms 19436 KB Output is correct
10 Correct 431 ms 19432 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 18 ms 1360 KB Output is correct
5 Correct 430 ms 19424 KB Output is correct
6 Correct 408 ms 19432 KB Output is correct
7 Correct 421 ms 19408 KB Output is correct
8 Correct 454 ms 19376 KB Output is correct
9 Correct 457 ms 19436 KB Output is correct
10 Correct 431 ms 19432 KB Output is correct
11 Correct 400 ms 18564 KB Output is correct
12 Correct 250 ms 9796 KB Output is correct
13 Correct 149 ms 3328 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 172 ms 3856 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 16 ms 512 KB Output is correct
19 Correct 163 ms 3528 KB Output is correct
20 Correct 152 ms 4192 KB Output is correct
21 Correct 140 ms 3328 KB Output is correct
22 Correct 164 ms 3072 KB Output is correct
23 Correct 162 ms 3328 KB Output is correct
24 Correct 162 ms 4348 KB Output is correct
25 Correct 430 ms 18616 KB Output is correct
26 Correct 238 ms 9800 KB Output is correct
27 Correct 146 ms 3328 KB Output is correct
28 Correct 163 ms 3200 KB Output is correct
29 Correct 161 ms 3328 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 15 ms 640 KB Output is correct
33 Correct 5 ms 256 KB Output is correct