Submission #149445

# Submission time Handle Problem Language Result Execution time Memory
149445 2019-09-01T06:29:56 Z 잉여로운 고3(#3749, imyujin, sebinkim) HicCup (FXCUP4_hiccup) C++17
24 / 100
43 ms 3456 KB
#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;

int HicCup(string S) {
	int N = S.size();
	int sum = 0;
	for(int i = 0; i < S.size(); i++) {
		if(S[i] == 'H') sum++;
		else if(S[i] == 'C') sum--;
		if(sum < 0) return -1;
	}
	if(sum != 0) return -1;
	int fc = S.size();
	for(int i = S.size() - 1; i >= 0; i--) if(S[i] == 'C') fc = i;
	if(fc == S.size()) return -1;
	for(int i = 0; i < fc; i++) if(S[i] == '!') return -1;

	int s = 0, e = S.size() - 1;
	while(s < e) {
		int m = (s + e + 1) / 2;
		int cnt = 0;
		bool b = true;
		for(int i = S.size() - 1; i >= 0; i--) {
			if(S[i] == '!') cnt++;
			else if(S[i] == 'C') cnt -= m;
			if(cnt < 0) b = false;
		}
		if(b) s = m;
		else e = m - 1;
	}
	return s;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:8:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < S.size(); i++) {
                 ~~^~~~~~~~~~
hiccup.cpp:16:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(fc == S.size()) return -1;
     ~~~^~~~~~~~~~~
hiccup.cpp:6:6: warning: unused variable 'N' [-Wunused-variable]
  int N = S.size();
      ^
# Verdict Execution time Memory Grader output
1 Correct 5 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 6 ms 512 KB Output is correct
5 Correct 41 ms 3328 KB Output is correct
6 Correct 13 ms 3200 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 42 ms 3200 KB Output is correct
9 Correct 43 ms 3328 KB Output is correct
10 Correct 12 ms 3328 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 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 6 ms 512 KB Output is correct
5 Correct 41 ms 3328 KB Output is correct
6 Correct 13 ms 3200 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 42 ms 3200 KB Output is correct
9 Correct 43 ms 3328 KB Output is correct
10 Correct 12 ms 3328 KB Output is correct
11 Correct 14 ms 3328 KB Output is correct
12 Correct 14 ms 3328 KB Output is correct
13 Correct 13 ms 3456 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Incorrect 35 ms 3328 KB Output isn't correct
16 Halted 0 ms 0 KB -