QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#559020 | #5981. Costly Binary Search | xiahaob | 0 | 0ms | 0kb | C++14 | 852b | 2024-09-11 19:42:55 | 2024-09-11 19:43:00 |
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...