QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#428640#5981. Costly Binary SearchQBF8 85ms548680kbC++20927b2024-06-01 20:46:302024-06-01 20:46:32

Judging History

This is the latest submission verdict.

  • [2024-06-01 20:46:32]
  • Judged
  • Verdict: 8
  • Time: 85ms
  • Memory: 548680kb
  • [2024-06-01 20:46:30]
  • Submitted

answer

#include<bits/stdc++.h>
#define ci const int
using namespace std;
ci N=1e6+5;
int n,a[N],l[130][N],r[130][N];
char s[N];
inline void Max(int &x,ci v){
	x=x>v?x:v;
}
inline void Min(int &x,ci v){
	x=x<v?x:v;
}
void Init(){
	for(int i=0;i<130;++i)
		for(int j=1;j<=n;++j)
			l[i][j]=r[i][j]=0;
}
void Work(){
	scanf("%s",s+1),n=strlen(s+1);
	for(int i=1;i<=n;++i)a[i]=s[i]^48;
	++n;
	for(int i=1;i<=n;++i)l[0][i]=r[0][i]=i;
	for(int T=1;;++T){
		for(int i=1;i<=n;++i)l[T][i]=l[T-1][i],r[T][i]=r[T-1][i];
		for(int i=1;i<n;++i)
			if(a[i]<=T)
				Max(r[T][l[T-a[i]][i]],r[T-a[i]][i+1]),
				Min(l[T][r[T-a[i]][i+1]],l[T-a[i]][i]);
		for(int i=2;i<=n;++i)Max(r[T][i],r[T][i-1]);
		for(int i=n-1;i;--i)Min(l[T][i],l[T][i+1]);
		if(r[T][1]==n){
			printf("%d\n",T);
			return;
		}
	}
}
int main(){
	int T;scanf("%d",&T);
	for(int i=1;i<=T;++i)printf("Case #%d: ",i),Work(),Init();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 85ms
memory: 548680kb

input:

50
8
5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...

output:

Case #1: 8
Case #2: 37
Case #3: 34
Case #4: 37
Case #5: 34
Case #6: 114
Case #7: 126
Case #8: 24
Case #9: 37
Case #10: 103
Case #11: 36
Case #12: 64
Case #13: 37
Case #14: 117
Case #15: 37
Case #16: 35
Case #17: 14
Case #18: 34
Case #19: 36
Case #20: 37
Case #21: 38
Case #22: 39
Case #23: 14
Case #2...

result:

ok 50 lines

Subtask #2:

score: 0
Runtime Error

Test #2:

score: 0
Runtime Error

input:

50
647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...

output:


result: