Submission #148644

#TimeUsernameProblemLanguageResultExecution timeMemory
148644お前はもう死んでいる (#200)HicCup (FXCUP4_hiccup)C++17
100 / 100
39 ms5492 KiB
#include "hiccup.h"

#include <vector>
#include <cassert>
#include <iostream>

int pos = 0;
char lookup(const std::string &S) {
	if(pos >= S.size()) {
		return '#';
	} else if(S[pos] == '!') {
		return '.';
	} else if(S[pos] == 'H') {
		return '(';
	} else {
		return ')';
	}
}

int solve(const std::string &S, bool good = false) {
	int ans = 0;
	int rest = 1e8;
	if(lookup(S) != '(') {
		return -1;
	}
	std::vector<int> wtf;
	while(1) {
		//std::cout << "lookup is " << lookup(S) << '\n';
		if(lookup(S) == '#') {
			return good ? std::min(ans, rest) : -1;
		} else if(lookup(S) == '(') {
			pos++;
			if(lookup(S) == '#' || lookup(S) == '.') {
				return -1;
			} else if(lookup(S) == '(') {
				rest = std::min(rest, solve(S));
				if(rest == -1) return -1;
				assert(lookup(S) == ')');
				pos++;
				if(wtf.empty()) {
					wtf.push_back(0);
				}
				ans = 0;
				wtf[0]++;
			} else if(lookup(S) == ')') {
				pos++;
				if(wtf.empty()) {
					wtf.push_back(0);
				}
				ans = 0;
				wtf[0]++;
			}
		} else if(lookup(S) == ')') {
			return std::min(ans, rest);
		} else if(lookup(S) == '.') {
			pos++;
			if(wtf.empty()) {
				return -1;
			}
			wtf[ans]--;
			if(ans + 1 >= wtf.size()) {
				wtf.push_back(0);
			}
			wtf[ans+1]++;
			if(wtf[ans] == 0) {
				ans++;
			}
		}
	}
}

int HicCup(std::string S) {
	int n = S.size();
	int ans = solve(S, true);
	if(pos != n) {
		ans = -1;
	}
	return ans;
}

Compilation message (stderr)

hiccup.cpp: In function 'char lookup(const string&)':
hiccup.cpp:9:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(pos >= S.size()) {
     ~~~~^~~~~~~~~~~
hiccup.cpp: In function 'int solve(const string&, bool)':
hiccup.cpp:61:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(ans + 1 >= wtf.size()) {
       ~~~~~~~~^~~~~~~~~~~~~
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...