QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561146#5981. Costly Binary Searchyqh202527 ✓10784ms110056kbC++141.8kb2024-09-12 20:38:532024-09-12 20:38:53

Judging History

你现在查看的是最新测评结果

  • [2024-09-12 20:38:53]
  • 评测
  • 测评结果:27
  • 用时:10784ms
  • 内存:110056kb
  • [2024-09-12 20:38:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10,V=180;
int n,c[N],id[V+10];
int L[12][N],R[12][N];
int s1[N],s2[N];
bool cmp(pair<int,int>x,pair<int,int>y){return x.second>y.second;}
void sol(int T){
	static char ch[N];scanf("%s",ch+1);
	n=strlen(ch+1);
	for(int i=0;i<=10;i++)for(int j=0;j<=n+1;j++)L[i][j]=R[i][j]=0;
	for(int i=1;i<=n;i++)c[i]=ch[i]-'0';
	for(int i=0;i<=n+1;i++)L[0][i]=i+1,R[0][i]=i-1;
	for(int i=0;i<=9;i++)id[i]=i;
	for(int i=10;i<=V;i++)id[i]=id[i-10];
	cout<<"Case #"<<T<<": ";
	for(int v=1;;v++){
		// vector<pair<int,int> >ve;
		for(int i=0;i<=n+1;i++)s1[i]=i-1,s2[i]=i+1;
		for(int i=1;i<=n;i++){
			if(v>=c[i]){
				int l=L[id[v-c[i]]][i-1],r=R[id[v-c[i]]][i+1];
				// ve.push_back({l,r});
				s1[l]=max(s1[l],r);
				s2[r]=min(s2[r],l);
				// if(v==8){
				// 	cout<<i<<" "<<l<<" "<<r<<endl;
				// }
			}
		}
		int mx=s1[0];
		// sort(ve.begin(),ve.end());
		for(int i=1,j=0;i<=n;i++){
			mx=max(mx,s1[i]);
			// while(j<ve.size()&&ve[j].first<=i)mx=max(mx,ve[j].second),j++;
			R[id[v]][i]=mx;
		}
		int mi=s2[n+1];
		// sort(ve.begin(),ve.end(),cmp);
		// for(pair<int,int>i:ve){
		// 	cout<<i.first<<" "<<i.second<<"  ";
		// }cout<<endl;
		for(int i=n,j=0;i>=0;i--){
			mi=min(mi,s2[i]);
			// while(j<ve.size()&&ve[j].second>=i)mi=min(mi,ve[j].first),j++;
			L[id[v]][i]=mi;
		}
		// if(v==23){
			// for(int i=1;i<=n;i++)cout<<L[id[v]][i]<<" ";
			// cout<<"  ";
			// // for(int i=1;i<=n;i++)cout<<R[id[v]][i]<<" ";
			// cout<<endl;
		// }
		if(R[id[v]][1]>=n||L[id[v]][n]<=1){
			cout<<v<<endl;
			memset(L,0,sizeof(L));
			memset(R,0,sizeof(R));
			return ;
		}
	}
}
signed main(){
	int t;cin>>t;
	for(int i=1;i<=t;i++)sol(i);
	return 0;
}
/*
g++ 1.cpp -o 1 -std=c++14 -O2 -Wall 
./1
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 465ms
memory: 102060kb

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: 19
Accepted

Test #2:

score: 19
Accepted
time: 10784ms
memory: 110056kb

input:

50
647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...

output:

Case #1: 42
Case #2: 43
Case #3: 120
Case #4: 42
Case #5: 43
Case #6: 43
Case #7: 31
Case #8: 43
Case #9: 171
Case #10: 42
Case #11: 39
Case #12: 42
Case #13: 42
Case #14: 44
Case #15: 39
Case #16: 20
Case #17: 180
Case #18: 30
Case #19: 45
Case #20: 43
Case #21: 44
Case #22: 31
Case #23: 83
Case #2...

result:

ok 50 lines

Extra Test:

score: 0
Extra Test Passed