답안 #150282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150282 2019-09-01T08:03:37 Z GucciBelt(#3697, PeppaPig, win11905, DodgeBallMan) HicCup (FXCUP4_hiccup) C++17
24 / 100
178 ms 6420 KB
#include "hiccup.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6+5;

int n;

bool checkFunction(string str, int mid) {
	stack<int> stk;
	for(int i = 0; i < n; ++i) {
		if(str[i] == 'C') stk.emplace(0);
		if(str[i] == '!') {
			if(stk.empty()) continue;
			int v = stk.top(); stk.pop();
			if(++v == mid) continue;
			stk.emplace(v);
		}
	}
	return stk.empty();
}

int HicCup(string S) {
	n = S.size();
	int cnt = 0;
	bool state = false;
	for(int i = 0; i < n; ++i) {
		if(S[i] == 'H') cnt++, state = false;
		if(S[i] == 'C') if(!~--cnt) return -1; else state = true;
		if(S[i] == '!') if(!state) return -1;	
	}
	if(cnt) return -1;
	int l = 0, r = S.size();
	while(l < r) {
		int mid = (l + r + 1) >> 1;
		if(checkFunction(S, mid)) l = mid;
		else r = mid-1;
	}	
	return l;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:30:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   if(S[i] == 'C') if(!~--cnt) return -1; else state = true;
     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 11 ms 640 KB Output is correct
5 Correct 178 ms 6420 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 176 ms 6400 KB Output is correct
9 Correct 177 ms 6368 KB Output is correct
10 Correct 15 ms 3328 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 11 ms 640 KB Output is correct
5 Correct 178 ms 6420 KB Output is correct
6 Correct 13 ms 3328 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 176 ms 6400 KB Output is correct
9 Correct 177 ms 6368 KB Output is correct
10 Correct 15 ms 3328 KB Output is correct
11 Correct 16 ms 3328 KB Output is correct
12 Correct 16 ms 3328 KB Output is correct
13 Correct 13 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 5 ms 432 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 83 ms 4352 KB Output is correct
20 Incorrect 84 ms 4396 KB Output isn't correct
21 Halted 0 ms 0 KB -