Submission #149231

# Submission time Handle Problem Language Result Execution time Memory
149231 2019-09-01T06:01:14 Z 샌즈뼈(#3582, exqt, esselem) HicCup (FXCUP4_hiccup) C++17
24 / 100
20 ms 3584 KB
#include "hiccup.h"
using namespace std;

int arr[500011]={};
int sz;

bool check(int k)
{
    int i,v=0;;
    for (i=sz;i>=1;i--)
    {
        if (arr[i]+v<k) return 0;
        v+=arr[i]-k;
    }
    return 1;
}

int HicCup(std::string S) {
	int N = S.size();
	int st=0,i,sum=0;

	for (char x:S)
    {
        if (x=='H') st++;
        if (x=='C')
        {
            if (!st--) return -1;
            sz++;
        }
        if (x=='!') { arr[sz]++; sum++;}
    }
    if (st) return -1;
    if (arr[0]) return -1;
    int l=0, r=sum/sz+1,mid;
    while(l+1<r)
    {
        mid=l+r>>1;
        if (check(mid)) l=mid;
        else r=mid;
    }

	return l;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:37:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         mid=l+r>>1;
             ~^~
hiccup.cpp:19:6: warning: unused variable 'N' [-Wunused-variable]
  int N = S.size();
      ^
hiccup.cpp:20:11: warning: unused variable 'i' [-Wunused-variable]
  int st=0,i,sum=0;
           ^
# 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 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 20 ms 3328 KB Output is correct
6 Correct 14 ms 3328 KB Output is correct
7 Correct 14 ms 3328 KB Output is correct
8 Correct 20 ms 3328 KB Output is correct
9 Correct 19 ms 3328 KB Output is correct
10 Correct 14 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 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 20 ms 3328 KB Output is correct
6 Correct 14 ms 3328 KB Output is correct
7 Correct 14 ms 3328 KB Output is correct
8 Correct 20 ms 3328 KB Output is correct
9 Correct 19 ms 3328 KB Output is correct
10 Correct 14 ms 3328 KB Output is correct
11 Correct 15 ms 3584 KB Output is correct
12 Correct 15 ms 3456 KB Output is correct
13 Correct 14 ms 3328 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Incorrect 17 ms 3200 KB Output isn't correct
16 Halted 0 ms 0 KB -