답안 #148540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148540 2019-09-01T04:37:50 Z 모현보유국(#3693, jhnah917, stonejjun03, ahgus89) HicCup (FXCUP4_hiccup) C++17
0 / 100
6 ms 384 KB
#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;

stack<int> stk;
string s;

bool chk(int x){
	int stk = 0;
	int save = 0;
	for(int i=0; i<s.size(); i++){
		if(s[i] == '!'){
			save++; continue;
		}
		if(s[i] == 'C'){
			stk++; continue;
		}
		if(stk <= 0) return 0;
		save -= x;
		if(save < 0) return 0;
	}
	return save >= 0;
}

int HicCup(string S) {
	reverse(S.begin(), S.end());
	s = S;
	int n = s.size();
	
	int ans = -1;
	int l = 0, r = 1000000;
	while(l <= r){
		int m = l + r >> 1;
		if(chk(m)){
			ans = m;
			l = m + 1;
		}else{
			r = m - 1;
		}
	}
	return ans;
}

Compilation message

hiccup.cpp: In function 'bool chk(int)':
hiccup.cpp:11:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<s.size(); i++){
               ~^~~~~~~~~
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:33:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l + r >> 1;
           ~~^~~
hiccup.cpp:28:6: warning: unused variable 'n' [-Wunused-variable]
  int n = s.size();
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -