답안 #149180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149180 2019-09-01T05:54:26 Z Torat(#3726, Osama_Alkhodairy, mohammedehab2002, mahmoudbadawy) HicCup (FXCUP4_hiccup) C++17
24 / 100
34 ms 9216 KB
#include "hiccup.h"
#include <bits/stdc++.h>

using namespace std;

const int N=1e6+6;

string s;
int n;
int nxt[N];

int can(int x)
{
	int cur=0,co=0,en=0,lsa=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='H'){lsa=0; co++;}
		else if(s[i]=='C')
		{
			if(co==0) return 0;
			en=1; cur=max(cur,i-1);
			for(int j=0;j<x;j++)
			{
				cur=nxt[cur];
				//cout << i << " " << cur << endl;
				if(cur>=n) return 0;
			}
			co--;
			lsa=1;
		}
		else
		{
			if(lsa==0) return 0;
		}
	}
	if(co) return 0;
	return 1;
}

int HicCup(std::string ss) {
	s=ss;
	n=s.size();
	nxt[n]=nxt[n+1]=nxt[n-1]=n+1;
	for(int i=n-2;i>=0;i--)
	{
		nxt[i]=nxt[i+1];
		if(s[i+1]=='!') nxt[i]=i+1;
	}
	/*for(int i=0;i<4;i++)
		cout << can(i) << endl;
	return 0;*/
	if(!can(0)) return -1;
	if(s==string(n,'!')) return -1;
	int mn=n,cura=0,curb=0;
	for(int i=n-1;i>=0;i--)
	{
		cura+=s[i]=='!';
		curb+=s[i]=='C';
		if(s[i]=='C') mn=min(mn,cura/curb);
	}
	return mn;
	int st=0,en=n,ans=-1;
	while(st<=en)
	{
		int mid=(st+en)/2;
		if(can(mid)){ans=mid; st=mid+1;}
		else en=mid-1;
	}
	while(can(ans+1)) ans++;
	while(ans>=0 &&(!can(ans))) ans--;
	return ans;
}

Compilation message

hiccup.cpp: In function 'int can(int)':
hiccup.cpp:14:17: warning: variable 'en' set but not used [-Wunused-but-set-variable]
  int cur=0,co=0,en=0,lsa=0;
                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 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 6 ms 688 KB Output is correct
5 Correct 32 ms 9216 KB Output is correct
6 Correct 18 ms 8192 KB Output is correct
7 Correct 20 ms 8192 KB Output is correct
8 Correct 34 ms 9216 KB Output is correct
9 Correct 34 ms 9216 KB Output is correct
10 Correct 19 ms 8192 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 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 6 ms 688 KB Output is correct
5 Correct 32 ms 9216 KB Output is correct
6 Correct 18 ms 8192 KB Output is correct
7 Correct 20 ms 8192 KB Output is correct
8 Correct 34 ms 9216 KB Output is correct
9 Correct 34 ms 9216 KB Output is correct
10 Correct 19 ms 8192 KB Output is correct
11 Correct 22 ms 8192 KB Output is correct
12 Correct 19 ms 8192 KB Output is correct
13 Correct 18 ms 8272 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 18 ms 8192 KB Output is correct
16 Correct 11 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 7 ms 1024 KB Output is correct
19 Correct 21 ms 9216 KB Output is correct
20 Incorrect 20 ms 9216 KB Output isn't correct
21 Halted 0 ms 0 KB -