QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559020#5981. Costly Binary Searchxiahaob0 0ms0kbC++14852b2024-09-11 19:42:552024-09-11 19:43:00

Judging History

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

  • [2024-09-11 19:43:00]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-09-11 19:42:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline int rd(){
	int s=0,w=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')w=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())s=s*10+ch-'0';
	return s*w;
}
const int N=1e6+5;
char a[N];int T,n,c[N];
int L[10][N],R[10][N];
inline int solve(){
	scanf("%s",a+1);
	n=strlen(a+1);
	for(int i=1;i<=n;++i)c[i]=a[i]-'0';
	for(int v=0;v<=181;++v){
		for(int i=0;i<=n+1;++i)L[v%10][i]=i+1,R[v%10][i]=i-1;
		for(int i=1;i<=n;++i){
			if(v<c[i])continue;
			int x=L[(v-c[i])%10][i-1],y=R[(v-c[i])%10][i+1];
			L[v][y]=x;R[v][x]=y;
		}
		for(int i=2;i<=n;++i)R[v][i]=max(R[v][i-1],R[v][i]);
		for(int i=n-1;i;--i)L[v][i]=min(L[v][i+1],L[v][i]);
		if(L[v][n]==1||R[v][1]==n)return v;
	}
}
int main(){
	T=rd();
	for(int i=1;i<=T;++i)printf("Case #%d: %d\n",i,solve());
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

50
8
5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #2:

score: 0
Runtime Error

input:

50
647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...

output:


result: