답안 #148522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148522 2019-09-01T04:35:46 Z 강력한 한방 필살기(#3595, gs14004, kriii, OnionPringles) HicCup (FXCUP4_hiccup) C++17
24 / 100
451 ms 19440 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 (u.size() >= 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 (u.size() >= 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 (u.size() >= 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 (u.size() >= 4 && u[z - 4].first == 'H' && u[z - 3].first == 'C' && u[z - 2].first == 0 && u[z - 1].first == '!' && u[z - 1].first == 0 && u[z - 2].second + u[z - 1].second >= m){
						int r = u[z - 2].first + u[z - 1].first - m;
						u.pop_back();
						u.pop_back();
						u.pop_back();
						u.pop_back();
						if (!u.empty() && u.back().first == 0) u.back().first += r;
						else u.push_back({ 0,r });
					}
					else if (u.size() >= 4 && u[z - 4].first == 'H' && u[z - 3].first == 'C' && u[z - 2].first == '!' && u[z - 1].first == 0 && u[z - 1].first == 0 && u[z - 2].second + u[z - 1].second >= m){
						int r = u[z - 2].first + u[z - 1].first - m;
						u.pop_back();
						u.pop_back();
						u.pop_back();
						u.pop_back();
						if (!u.empty() && u.back().first == 0) u.back().first += r;
						else u.push_back({ 0,r });
					}
					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;
}
# 결과 실행 시간 메모리 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 1392 KB Output is correct
5 Correct 421 ms 19440 KB Output is correct
6 Correct 410 ms 19384 KB Output is correct
7 Correct 423 ms 19400 KB Output is correct
8 Correct 451 ms 19440 KB Output is correct
9 Correct 429 ms 19240 KB Output is correct
10 Correct 427 ms 19440 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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 1392 KB Output is correct
5 Correct 421 ms 19440 KB Output is correct
6 Correct 410 ms 19384 KB Output is correct
7 Correct 423 ms 19400 KB Output is correct
8 Correct 451 ms 19440 KB Output is correct
9 Correct 429 ms 19240 KB Output is correct
10 Correct 427 ms 19440 KB Output is correct
11 Correct 399 ms 18692 KB Output is correct
12 Correct 238 ms 9816 KB Output is correct
13 Correct 132 ms 3200 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 144 ms 3672 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 128 KB Output is correct
18 Correct 16 ms 768 KB Output is correct
19 Incorrect 150 ms 3528 KB Output isn't correct
20 Halted 0 ms 0 KB -