Submission #148449

# Submission time Handle Problem Language Result Execution time Memory
148449 2019-09-01T04:25:38 Z 모현보유국(#3693, jhnah917, stonejjun03, ahgus89) HicCup (FXCUP4_hiccup) C++17
0 / 100
147 ms 4472 KB
#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;

stack<int> stk;
string s;

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

int HicCup(string S) {
	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:30:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l + r >> 1;
           ~~^~~
hiccup.cpp:25:6: warning: unused variable 'n' [-Wunused-variable]
  int n = s.size();
      ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
5 Correct 147 ms 4352 KB Output is correct
6 Correct 16 ms 4352 KB Output is correct
7 Correct 15 ms 4224 KB Output is correct
8 Correct 141 ms 4096 KB Output is correct
9 Correct 146 ms 4224 KB Output is correct
10 Correct 15 ms 4272 KB Output is correct
11 Incorrect 5 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
5 Correct 147 ms 4352 KB Output is correct
6 Correct 16 ms 4352 KB Output is correct
7 Correct 15 ms 4224 KB Output is correct
8 Correct 141 ms 4096 KB Output is correct
9 Correct 146 ms 4224 KB Output is correct
10 Correct 15 ms 4272 KB Output is correct
11 Correct 33 ms 4352 KB Output is correct
12 Correct 30 ms 4352 KB Output is correct
13 Correct 17 ms 4352 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 42 ms 4472 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Incorrect 39 ms 4368 KB Output isn't correct
20 Halted 0 ms 0 KB -