답안 #150076

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

using namespace std;

const int N = 1e6+5;

int HicCup(string S) {
	stack<int> stk;
	for(int i = 0; i < S.size()-1; i++) if(S[i] == 'H' && S[i+1] == '!')
		return -1;
	for(int i = 0; i < S.size(); i++) {
		if(S[i] == 'H') stk.emplace(i);
		else if(S[i] == 'C') {
			if(stk.empty()) return -1;
			else stk.pop();
		}
	}
	if(!stk.empty()) return -1;
	int l = 0, r = S.size();
	while(l < r) {
		int mid = (l + r + 1) >> 1;
		queue<int> Q;
		bool chk = false;
		for(int i = 0; i < S.size(); i++) {
			if(S[i] == 'C') {
				chk = true;
				Q.emplace(0);
			} else if(S[i] == '!') {
				if(Q.empty() && !chk) return -1;
				else if(!Q.empty()) {
					int now = Q.front(); Q.pop();
					if(now + 1 < mid) Q.emplace(now + 1);
				}
			}
		}
		if(Q.empty()) l = mid;
		else r = mid - 1;
	}	
	return l;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:10:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < S.size()-1; i++) if(S[i] == 'H' && S[i+1] == '!')
                 ~~^~~~~~~~~~~~
hiccup.cpp:12:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < S.size(); i++) {
                 ~~^~~~~~~~~~
hiccup.cpp:25:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < S.size(); i++) {
                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 11 ms 640 KB Output is correct
5 Correct 214 ms 5448 KB Output is correct
6 Correct 19 ms 3328 KB Output is correct
7 Correct 19 ms 3328 KB Output is correct
8 Correct 227 ms 5448 KB Output is correct
9 Correct 230 ms 5444 KB Output is correct
10 Correct 20 ms 3328 KB Output is correct
11 Correct 6 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 5 ms 384 KB Output is correct
4 Correct 11 ms 640 KB Output is correct
5 Correct 214 ms 5448 KB Output is correct
6 Correct 19 ms 3328 KB Output is correct
7 Correct 19 ms 3328 KB Output is correct
8 Correct 227 ms 5448 KB Output is correct
9 Correct 230 ms 5444 KB Output is correct
10 Correct 20 ms 3328 KB Output is correct
11 Correct 17 ms 3328 KB Output is correct
12 Correct 15 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 12 ms 3328 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 123 ms 3200 KB Output is correct
20 Incorrect 135 ms 3444 KB Output isn't correct
21 Halted 0 ms 0 KB -