답안 #148644

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148644 2019-09-01T04:51:01 Z お前はもう死んでいる(#3784, kuroni, nvmdava, tfg) HicCup (FXCUP4_hiccup) C++17
100 / 100
39 ms 5492 KB
#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

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()) {
       ~~~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 304 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 36 ms 3456 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 39 ms 3456 KB Output is correct
9 Correct 36 ms 3452 KB Output is correct
10 Correct 13 ms 3200 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 304 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 36 ms 3456 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 39 ms 3456 KB Output is correct
9 Correct 36 ms 3452 KB Output is correct
10 Correct 13 ms 3200 KB Output is correct
11 Correct 16 ms 3200 KB Output is correct
12 Correct 17 ms 3328 KB Output is correct
13 Correct 14 ms 3328 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 13 ms 3328 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 20 ms 3200 KB Output is correct
20 Correct 21 ms 3328 KB Output is correct
21 Correct 21 ms 3328 KB Output is correct
22 Correct 24 ms 4872 KB Output is correct
23 Correct 25 ms 5492 KB Output is correct
24 Correct 21 ms 3328 KB Output is correct
25 Correct 34 ms 3328 KB Output is correct
26 Correct 23 ms 3328 KB Output is correct
27 Correct 21 ms 3200 KB Output is correct
28 Correct 21 ms 3328 KB Output is correct
29 Correct 22 ms 4472 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
33 Correct 5 ms 384 KB Output is correct