Submission #147986

# Submission time Handle Problem Language Result Execution time Memory
147986 2019-08-31T10:33:06 Z imsifile HicCup (FXCUP4_hiccup) C++17
100 / 100
64 ms 4288 KB
#include "hiccup.h"
using namespace std;
 
char ch[1010101];
int am[1010101], scn;
 
bool isok(int N, string &S, int K){
	scn=0;
	for(int i=0; i<N; i++){
		if(S[i]=='H') ch[scn]='H', am[scn++]=0;
		if(S[i]=='C'){
			while(1){
				if(!scn || ch[scn-1]=='C') return 0;
				scn--;
				if(ch[scn]=='H') break;
				if(ch[scn]=='X' && am[scn]) return 0;
			}
			if(scn && ch[scn-1]=='X') am[scn-1]+=K;
			else ch[scn]='X', am[scn++]=K;
		}
		if(S[i]=='!'){
			if(!scn || ch[scn-1]!='X') return 0;
			am[scn-1]--;
			if(am[scn-1]<0) am[scn-1]=0;
		}
	}
	while(scn){
		scn--;
		if(ch[scn]=='H' || ch[scn]=='C') return 0;
		if(ch[scn]=='X' && am[scn]) return 0;
	}
	return 1;
}
 
int HicCup(string S) {
	int N=S.size();
	int mi=0, mx=N, md, dap=-1;
	while(mi<=mx){
		md=(mi+mx)/2;
		if(isok(N, S, md)) dap=md, mi=md+1;
		else mx=md-1;
	}
	return dap;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 19 ms 4216 KB Output is correct
6 Correct 9 ms 4220 KB Output is correct
7 Correct 9 ms 4216 KB Output is correct
8 Correct 19 ms 4216 KB Output is correct
9 Correct 19 ms 4216 KB Output is correct
10 Correct 9 ms 4216 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 19 ms 4216 KB Output is correct
6 Correct 9 ms 4220 KB Output is correct
7 Correct 9 ms 4216 KB Output is correct
8 Correct 19 ms 4216 KB Output is correct
9 Correct 19 ms 4216 KB Output is correct
10 Correct 9 ms 4216 KB Output is correct
11 Correct 10 ms 4216 KB Output is correct
12 Correct 13 ms 4216 KB Output is correct
13 Correct 13 ms 4204 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 10 ms 4260 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 29 ms 4216 KB Output is correct
20 Correct 20 ms 4220 KB Output is correct
21 Correct 45 ms 4216 KB Output is correct
22 Correct 43 ms 4088 KB Output is correct
23 Correct 64 ms 4216 KB Output is correct
24 Correct 17 ms 4188 KB Output is correct
25 Correct 18 ms 4288 KB Output is correct
26 Correct 18 ms 4288 KB Output is correct
27 Correct 55 ms 4216 KB Output is correct
28 Correct 62 ms 4088 KB Output is correct
29 Correct 64 ms 4216 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 6 ms 632 KB Output is correct
33 Correct 2 ms 256 KB Output is correct