QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560700#5981. Costly Binary Searchyqh20250 21879ms100048kbC++141.6kb2024-09-12 17:27:102024-09-12 17:27:10

Judging History

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

  • [2024-09-12 17:27:10]
  • 评测
  • 测评结果:0
  • 用时:21879ms
  • 内存:100048kb
  • [2024-09-12 17:27:10]
  • 提交

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=1;j<=n;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<=V;v++){
		// vector<pair<int,int> >ve;
		for(int i=0;i<=n+1;i++)s1[i]=0,s2[i]=n+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);
				// cout<<i<<" "<<l<<" "<<r<<endl;
			}
		}
		int mx=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=n;
		// 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;
		}
		// 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){
			cout<<v<<endl;
			return ;
		}
	}
	cout<<0<<endl;
}
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: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 171ms
memory: 53048kb

input:

50
8
5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...

output:

Case #1: 8
Case #2: 0
Case #3: 0
Case #4: 0
Case #5: 0
Case #6: 0
Case #7: 0
Case #8: 24
Case #9: 0
Case #10: 0
Case #11: 0
Case #12: 0
Case #13: 0
Case #14: 0
Case #15: 0
Case #16: 0
Case #17: 14
Case #18: 0
Case #19: 0
Case #20: 0
Case #21: 0
Case #22: 0
Case #23: 14
Case #24: 9
Case #25: 0
Case #...

result:

wrong answer 2nd lines differ - expected: 'Case #2: 37', found: 'Case #2: 0'

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 21879ms
memory: 100048kb

input:

50
647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...

output:

Case #1: 0
Case #2: 0
Case #3: 119
Case #4: 0
Case #5: 0
Case #6: 0
Case #7: 0
Case #8: 0
Case #9: 0
Case #10: 0
Case #11: 0
Case #12: 0
Case #13: 0
Case #14: 0
Case #15: 0
Case #16: 20
Case #17: 0
Case #18: 0
Case #19: 0
Case #20: 0
Case #21: 0
Case #22: 0
Case #23: 0
Case #24: 0
Case #25: 0
Case #...

result:

wrong answer 1st lines differ - expected: 'Case #1: 42', found: 'Case #1: 0'