QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#562630 | #5981. Costly Binary Search | OFforest_1273 | 27 ✓ | 10814ms | 133832kb | C++14 | 1.2kb | 2024-09-13 19:35:47 | 2024-09-13 19:35:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template<typename T> inline void read(T &x){x=0;int f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();x*=f;}
template<typename T> inline void write(T x){if(x>9)write(x/10);putchar(x%10+'0');}
const int N=1e6+10;
int T,n,L[15][N],R[15][N],c[N],sl[N],sr[N];
char s[N];
void solve(int T){
printf("Case #%d: ",T),scanf("%s",s+1),n=strlen(s+1),memset(L,0,sizeof(L)),memset(R,0,sizeof(R));
for(int i=1;i<=n;++i)c[i]=s[i]-'0';
for(int i=0;i<=n+1;++i)L[0][i]=i+1,R[0][i]=i-1;
for(int x=1;;++x){
for(int i=0;i<=n+1;++i)sl[i]=i-1,sr[i]=i+1;
for(int i=1;i<=n;++i)if(x>=c[i])
sl[L[(x-c[i])%10][i-1]]=max(sl[L[(x-c[i])%10][i-1]],R[(x-c[i])%10][i+1]),
sr[R[(x-c[i])%10][i+1]]=min(sr[R[(x-c[i])%10][i+1]],L[(x-c[i])%10][i-1]);
int mx=sl[0],mn=sr[n+1];
for(int i=1;i<=n;++i)mx=max(mx,sl[i]),R[x%10][i]=mx;
for(int i=n;~i;--i)mn=min(mn,sr[i]),L[x%10][i]=mn;
if(L[x%10][n]<=1||R[x%10][1]>=n)return write(x),putchar('\n'),void();
}
}
int main(){
read(T);
for(int i=1;i<=T;++i)solve(i);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 499ms
memory: 123004kb
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: 10814ms
memory: 133832kb
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